Dynamic array based on blocks of fixed size. More...
Go to the source code of this file.
Data Structures | |
struct | tommy_arrayblkof_struct |
Array container type. More... | |
Macros | |
#define | TOMMY_ARRAYBLKOF_SIZE (4 * 1024) |
Elements for each block. More... | |
Typedefs | |
typedef struct tommy_arrayblkof_struct | tommy_arrayblkof |
Array container type. More... | |
Functions | |
void | tommy_arrayblkof_init (tommy_arrayblkof *array, tommy_size_t element_size) |
Initializes the array. More... | |
void | tommy_arrayblkof_done (tommy_arrayblkof *array) |
Deinitializes the array. More... | |
void | tommy_arrayblkof_grow (tommy_arrayblkof *array, tommy_count_t size) |
Grows the size up to the specified value. More... | |
void * | tommy_arrayblkof_ref (tommy_arrayblkof *array, tommy_count_t pos) |
Gets a reference of the element at the specified position. More... | |
tommy_count_t | tommy_arrayblkof_size (tommy_arrayblkof *array) |
Gets the initialized size of the array. More... | |
tommy_size_t | tommy_arrayblkof_memory_usage (tommy_arrayblkof *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.
This is very similar at tommy_arrayblk, but it allows to store elements of any size and not just pointers.
Note that in this case tommy_arrayblkof_ref() returns a pointer to the element, that should be used for getting and setting elements in the array, as generic getter and setter are not available.
#define TOMMY_ARRAYBLKOF_SIZE (4 * 1024) |
Elements for each block.
typedef struct tommy_arrayblkof_struct tommy_arrayblkof |
Array container type.
void tommy_arrayblkof_init | ( | tommy_arrayblkof * | array, |
tommy_size_t | element_size | ||
) |
Initializes the array.
element_size | Size in byte of the element to store in the array. |
void tommy_arrayblkof_done | ( | tommy_arrayblkof * | array | ) |
Deinitializes the array.
void tommy_arrayblkof_grow | ( | tommy_arrayblkof * | 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_arrayblkof_ref | ( | tommy_arrayblkof * | 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_arrayblkof_grow().
tommy_count_t tommy_arrayblkof_size | ( | tommy_arrayblkof * | array | ) |
Gets the initialized size of the array.
tommy_size_t tommy_arrayblkof_memory_usage | ( | tommy_arrayblkof * | array | ) |
Gets the size of allocated memory.