49
void init_dynamic_array2(DYNAMIC_ARRAY *array, uint32_t element_size,
50
void *init_buffer, uint32_t init_alloc,
51
uint32_t alloc_increment)
49
static void init_dynamic_array2(DYNAMIC_ARRAY* array, uint32_t element_size, uint32_t init_alloc, uint32_t alloc_increment)
53
51
if (!alloc_increment)
55
alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16U);
53
alloc_increment= max((8192 - MALLOC_OVERHEAD) / element_size, 16U);
56
54
if (init_alloc > 8 && alloc_increment > init_alloc * 2)
57
alloc_increment=init_alloc*2;
62
init_alloc=alloc_increment;
55
alloc_increment= init_alloc * 2;
58
init_alloc= alloc_increment;
65
59
array->set_size(0);
66
array->max_element=init_alloc;
67
array->alloc_increment=alloc_increment;
68
array->size_of_element=element_size;
69
if ((array->buffer= (unsigned char*) init_buffer))
71
array->buffer= (unsigned char*) malloc(element_size*init_alloc);
60
array->max_element= init_alloc;
61
array->alloc_increment= alloc_increment;
62
array->size_of_element= element_size;
63
array->buffer= (unsigned char*) malloc(element_size * init_alloc);
66
void DYNAMIC_ARRAY::init(uint32_t element_size, uint32_t init_alloc, uint32_t alloc_increment0)
68
init_dynamic_array2(this, element_size, init_alloc, alloc_increment0);
87
static void insert_dynamic(DYNAMIC_ARRAY *array, void* element)
84
static void insert_dynamic(DYNAMIC_ARRAY* array, void* element)
89
86
unsigned char* buffer;
90
87
if (array->size() == array->max_element)
91
buffer= alloc_dynamic(array);
88
buffer= array->alloc();
94
91
buffer= array->buffer+(array->size() * array->size_of_element);
123
unsigned char *alloc_dynamic(DYNAMIC_ARRAY *array)
120
static unsigned char* alloc_dynamic(DYNAMIC_ARRAY* array)
125
122
if (array->size() == array->max_element)
128
if (array->buffer == (unsigned char *)(array + 1))
125
if (array->buffer == (unsigned char*)(array + 1))
131
128
In this senerio, the buffer is statically preallocated,
151
153
array Array to be deleted
154
void delete_dynamic(DYNAMIC_ARRAY *array)
156
static void delete_dynamic(DYNAMIC_ARRAY* array)
157
159
Just mark as empty if we are using a static buffer
159
if (array->buffer == (unsigned char *)(array + 1))
161
if (array->buffer == (unsigned char*)(array + 1))
160
162
array->set_size(0);
163
else if (array->buffer)
164
165
free(array->buffer);