Dynamic array based on segments of exponentially growing size. More...
Go to the source code of this file.
Data Structures | |
| struct | tommy_array_struct |
| Array container type. More... | |
Macros | |
| #define | TOMMY_ARRAY_BIT 6 |
| Initial and minimal size of the array expressed as a power of 2. More... | |
Typedefs | |
| typedef struct tommy_array_struct | tommy_array |
| Array container type. More... | |
Functions | |
| TOMMY_API void | tommy_array_init (tommy_array *array) |
| Initializes the array. More... | |
| TOMMY_API void | tommy_array_done (tommy_array *array) |
| Deinitializes the array. More... | |
| TOMMY_API void | tommy_array_grow (tommy_array *array, tommy_size_t size) |
| Grows the size up to the specified value. More... | |
| void ** | tommy_array_ref (tommy_array *array, tommy_size_t pos) |
| Gets a reference of the element at the specified position. More... | |
| void | tommy_array_set (tommy_array *array, tommy_size_t pos, void *element) |
| Sets the element at the specified position. More... | |
| void * | tommy_array_get (tommy_array *array, tommy_size_t pos) |
| Gets the element at the specified position. More... | |
| void | tommy_array_insert (tommy_array *array, void *element) |
| Grows and inserts a new element at the end of the array. More... | |
| tommy_size_t | tommy_array_size (tommy_array *array) |
| Gets the initialized size of the array. More... | |
| TOMMY_API tommy_size_t | tommy_array_memory_usage (tommy_array *array) |
| Gets the size of allocated memory. More... | |
Dynamic array based on segments of exponentially growing size.
This array is able to grow dynamically upon request, without any reallocation.
The grow operation involves an allocation of a new array segment, without reallocating the already used memory, and thus not increasing the heap fragmentation. This also implies that the address of the stored elements never change.
Allocated segments grow in size exponentially.
| #define TOMMY_ARRAY_BIT 6 |
Initial and minimal size of the array expressed as a power of 2.
The initial size is 2^TOMMY_ARRAY_BIT.
| typedef struct tommy_array_struct tommy_array |
Array container type.
| TOMMY_API void tommy_array_init | ( | tommy_array * | array | ) |
Initializes the array.
| TOMMY_API void tommy_array_done | ( | tommy_array * | array | ) |
Deinitializes the array.
| TOMMY_API void tommy_array_grow | ( | tommy_array * | array, |
| tommy_size_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_array_ref | ( | tommy_array * | array, |
| tommy_size_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_array_grow().
| void tommy_array_set | ( | tommy_array * | array, |
| tommy_size_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_array_grow().
| void * tommy_array_get | ( | tommy_array * | array, |
| tommy_size_t | pos | ||
| ) |
Gets the element at the specified position.
You must be sure that space for this position is already allocated calling tommy_array_grow().
| void tommy_array_insert | ( | tommy_array * | array, |
| void * | element | ||
| ) |
Grows and inserts a new element at the end of the array.
| tommy_size_t tommy_array_size | ( | tommy_array * | array | ) |
Gets the initialized size of the array.
| TOMMY_API tommy_size_t tommy_array_memory_usage | ( | tommy_array * | array | ) |
Gets the size of allocated memory.