Dynamic array based on blocks of fixed size. More...
Go to the source code of this file.
Data Structures | |
struct | tommy_arrayblk_struct |
Array container type. More... | |
Macros | |
#define | TOMMY_ARRAYBLK_SIZE (4 * 1024) |
Elements for each block. More... | |
Typedefs | |
typedef struct tommy_arrayblk_struct | tommy_arrayblk |
Array container type. More... | |
Functions | |
void | tommy_arrayblk_init (tommy_arrayblk *array) |
Initializes the array. More... | |
void | tommy_arrayblk_done (tommy_arrayblk *array) |
Deinitializes the array. More... | |
void | tommy_arrayblk_grow (tommy_arrayblk *array, tommy_count_t size) |
Grows the size up to the specified value. More... | |
void ** | tommy_arrayblk_ref (tommy_arrayblk *array, tommy_count_t pos) |
Gets a reference of the element at the specified position. More... | |
void | tommy_arrayblk_set (tommy_arrayblk *array, tommy_count_t pos, void *element) |
Sets the element at the specified position. More... | |
void * | tommy_arrayblk_get (tommy_arrayblk *array, tommy_count_t pos) |
Gets the element at the specified position. More... | |
void | tommy_arrayblk_insert (tommy_arrayblk *array, void *element) |
Grows and inserts a new element at the end of the array. More... | |
tommy_count_t | tommy_arrayblk_size (tommy_arrayblk *array) |
Gets the initialized size of the array. More... | |
tommy_size_t | tommy_arrayblk_memory_usage (tommy_arrayblk *array) |
Gets the size of allocated memory. More... | |
Dynamic array based on blocks of fixed size.
This array is able to grow dynamically upon request, without any reallocation.
The grow operation involves an allocation of a new array block, without reallocating the already used memory, and then not increasing the heap fragmentation, and minimize the space occupation. This also implies that the address of the stored elements never change.
Allocated blocks are always of the same fixed size of 4 Ki pointers.
#define TOMMY_ARRAYBLK_SIZE (4 * 1024) |
Elements for each block.
typedef struct tommy_arrayblk_struct tommy_arrayblk |
Array container type.
void tommy_arrayblk_init | ( | tommy_arrayblk * | array | ) |
Initializes the array.
void tommy_arrayblk_done | ( | tommy_arrayblk * | array | ) |
Deinitializes the array.
void tommy_arrayblk_grow | ( | tommy_arrayblk * | array, |
tommy_count_t | size | ||
) |
Grows the size up to the specified value.
All the new elements in the array are initialized with the 0 value.
void** tommy_arrayblk_ref | ( | tommy_arrayblk * | array, |
tommy_count_t | pos | ||
) |
Gets a reference of the element at the specified position.
You must be sure that space for this position is already allocated calling tommy_arrayblk_grow().
void tommy_arrayblk_set | ( | tommy_arrayblk * | array, |
tommy_count_t | pos, | ||
void * | element | ||
) |
Sets the element at the specified position.
You must be sure that space for this position is already allocated calling tommy_arrayblk_grow().
void* tommy_arrayblk_get | ( | tommy_arrayblk * | array, |
tommy_count_t | pos | ||
) |
Gets the element at the specified position.
You must be sure that space for this position is already allocated calling tommy_arrayblk_grow().
void tommy_arrayblk_insert | ( | tommy_arrayblk * | array, |
void * | element | ||
) |
Grows and inserts a new element at the end of the array.
tommy_count_t tommy_arrayblk_size | ( | tommy_arrayblk * | array | ) |
Gets the initialized size of the array.
tommy_size_t tommy_arrayblk_memory_usage | ( | tommy_arrayblk * | array | ) |
Gets the size of allocated memory.