acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
aaa_tiny_array_impl.h
1// Created by camilo on 2021-03-09 00:43 BRT <3ThomasBS_!!
2
3
4template < typename TYPE >
5void tiny_array < TYPE > ::allocate(::i32 iCount)
6{
7
8 if (iCount < 0)
9 {
10
11 throw ::exception(error_bad_argument);
12
13 return;
14
15 }
16
17 if (iCount > TINY_ARRAY_BUILTIN_SIZE || m_iAllocation > 0)
18 {
19
20 if (m_iAllocation <= 0)
21 {
22
23 auto p = (TYPE *) ::system()->m_pheapmanagement->memory(::heap::e_memory_main)->allocate(sizeof(TYPE) * iCount);
24
25 ::zero(p, sizeof(TYPE) * iCount);
26
27 m_iAllocation = iCount;
28
29 m_p = p;
30
31 }
32
33 else if (iCount > m_iAllocation)
34 {
35
36 auto p = (TYPE *) memory_reallocate(m_p, sizeof(TYPE) * iCount);
37
38 ::zero(p + m_iCount, sizeof(TYPE) * (iCount - m_iAllocation));
39
40 m_iAllocation = iCount;
41
42 m_p = p;
43
44 }
45
46 }
47 else
48 {
49
50 m_p = m_typea;
51
52 }
53
54 m_iCount = iCount;
55
56}
57
58
59template < typename TYPE >
60void tiny_array < TYPE > ::free()
61{
62
63 if (m_iAllocation > 0)
64 {
65
66 ::system()->m_pheapmanagement->memory(::heap::e_memory_main)->free(m_p);
67
68 }
69
70 m_iCount = 0;
71
72 m_iAllocation = 0;
73
74 m_p = nullptr;
75
76}
77
78
79template < typename TYPE >
80void tiny_array < TYPE > ::zero()
81{
82
83 ::zero(m_p, sizeof(TYPE) * m_iCount);
84
85}
86
87
88template < typename TYPE >
89void tiny_array < TYPE > ::set_at_grow(::i32 iIndex, const TYPE& t)
90{
91
92 element_at_grow(iIndex) = t;
93
94}
95
96
97template < typename TYPE >
98TYPE & tiny_array < TYPE > ::element_at_grow(::i32 iIndex)
99{
100
101 if (iIndex < 0)
102 {
103
104 throw ::exception(error_bad_argument);
105
106 }
107
108 if (iIndex >= m_iCount)
109 {
110
111 allocate(iIndex + 1);
112
113 }
114
115 return m_p[iIndex];
116
117}
118
119
120