|
@@ -28,11 +28,14 @@ cmAr_t* _cmArHandleToPtr( cmArrayH_t h )
|
28
|
28
|
cmArRC_t _cmArFree( cmAr_t* p )
|
29
|
29
|
{
|
30
|
30
|
cmArRC_t rc = kOkArRC;
|
|
31
|
+ cmMemFree(p->base);
|
31
|
32
|
cmMemFree(p);
|
32
|
33
|
return rc;
|
33
|
34
|
}
|
34
|
35
|
|
35
|
|
-cmArRC_t cmArrayAlloc( cmCtx_t* ctx, cmArrayH_t* hp, unsigned initCnt, unsigned expandCnt, unsigned eleByteCnt )
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+cmArRC_t cmArrayAlloc0( cmCtx_t* ctx, cmArrayH_t* hp, unsigned eleByteCnt, unsigned initCnt, unsigned expandCnt )
|
36
|
39
|
{
|
37
|
40
|
cmArRC_t rc;
|
38
|
41
|
if((rc = cmArrayRelease(hp)) != kOkArRC )
|
|
@@ -54,6 +57,10 @@ cmArRC_t cmArrayAlloc( cmCtx_t* ctx, cmArrayH_t* hp, unsigned initCnt, unsig
|
54
|
57
|
return rc;
|
55
|
58
|
}
|
56
|
59
|
|
|
60
|
+cmArRC_t cmArrayAlloc( cmCtx_t* ctx, cmArrayH_t* hp, unsigned eleByteCnt )
|
|
61
|
+{ return cmArrayAlloc0(ctx,hp,eleByteCnt,10,10); }
|
|
62
|
+
|
|
63
|
+
|
57
|
64
|
cmArRC_t cmArrayRelease( cmArrayH_t* hp )
|
58
|
65
|
{
|
59
|
66
|
cmArRC_t rc = kOkArRC;
|
|
@@ -74,6 +81,18 @@ cmArRC_t cmArrayRelease( cmArrayH_t* hp )
|
74
|
81
|
cmArRC_t cmArrayIsValid(cmArrayH_t h )
|
75
|
82
|
{ return h.h != NULL; }
|
76
|
83
|
|
|
84
|
+void cmArraySetExpandCount( cmArrayH_t h, unsigned expandCnt )
|
|
85
|
+{
|
|
86
|
+ cmAr_t* p = _cmArHandleToPtr(h);
|
|
87
|
+ p->expand_cnt = expandCnt;
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+unsigned cmArrayExpandCount( cmArrayH_t h )
|
|
91
|
+{
|
|
92
|
+ cmAr_t* p = _cmArHandleToPtr(h);
|
|
93
|
+ return p->expand_cnt;
|
|
94
|
+}
|
|
95
|
+
|
77
|
96
|
unsigned cmArrayCount( cmArrayH_t h )
|
78
|
97
|
{
|
79
|
98
|
cmAr_t* p = _cmArHandleToPtr(h);
|
|
@@ -99,15 +118,20 @@ void* _cmArraySet( cmAr_t* p, unsigned idx, const void* data, unsigned dataEl
|
99
|
118
|
{
|
100
|
119
|
unsigned add_cnt = (idx + dataEleCnt) - p->alloc_cnt;
|
101
|
120
|
|
102
|
|
- p->alloc_cnt += ((add_cnt / p->expand_cnt) + 1) * p->expand_cnt;
|
|
121
|
+ if( add_cnt < p->expand_cnt )
|
|
122
|
+ add_cnt = p->expand_cnt;
|
|
123
|
+ else
|
|
124
|
+ add_cnt = ((add_cnt / p->expand_cnt) + 1) * p->expand_cnt;
|
|
125
|
+
|
|
126
|
+ p->alloc_cnt += add_cnt;
|
103
|
127
|
|
104
|
|
- p->base = cmMemResizePZ(char,p->base,p->alloc_cnt);
|
|
128
|
+ p->base = cmMemResizePZ(char,p->base,p->alloc_cnt*p->ele_byte_cnt);
|
105
|
129
|
}
|
106
|
130
|
|
107
|
131
|
char* bp = p->base + (idx*p->ele_byte_cnt);
|
108
|
132
|
|
109
|
133
|
if( data == NULL )
|
110
|
|
- memset(bp, 0, p->ele_byte_cnt * dataEleCnt );
|
|
134
|
+ memset(bp, 0, p->ele_byte_cnt * dataEleCnt );
|
111
|
135
|
else
|
112
|
136
|
memcpy(bp, data, p->ele_byte_cnt * dataEleCnt );
|
113
|
137
|
|