Dynamic array based on segments of exponentially growing size. More...
Go to the source code of this file.
Data Structures | |
| struct | tommy_arrayof_struct |
| Array container type. More... | |
Macros | |
| #define | TOMMY_ARRAYOF_BIT 6 |
| Initial and minimal size of the array expressed as a power of 2. More... | |
Typedefs | |
| typedef struct tommy_arrayof_struct | tommy_arrayof |
| Array container type. More... | |
Functions | |
| TOMMY_API void | tommy_arrayof_init (tommy_arrayof *array, tommy_size_t element_size) |
| Initializes the array. More... | |
| TOMMY_API void | tommy_arrayof_done (tommy_arrayof *array) |
| Deinitializes the array. More... | |
| TOMMY_API void | tommy_arrayof_grow (tommy_arrayof *array, tommy_size_t size) |
| Grows the size up to the specified value. More... | |
| void * | tommy_arrayof_ref (tommy_arrayof *array, tommy_size_t pos) |
| Gets a reference of the element at the specified position. More... | |
| tommy_size_t | tommy_arrayof_size (tommy_arrayof *array) |
| Gets the initialized size of the array. More... | |
| TOMMY_API tommy_size_t | tommy_arrayof_memory_usage (tommy_arrayof *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.
This is very similar to tommy_array, but it allows to store elements of any size and not just pointers.
Note that in this case tommy_arrayof_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_ARRAYOF_BIT 6 |
Initial and minimal size of the array expressed as a power of 2.
The initial size is 2^TOMMY_ARRAYOF_BIT.
| typedef struct tommy_arrayof_struct tommy_arrayof |
Array container type.
| TOMMY_API void tommy_arrayof_init | ( | tommy_arrayof * | array, |
| tommy_size_t | element_size | ||
| ) |
Initializes the array.
| array | Array to initialize. |
| element_size | Size in bytes of the element to store in the array. |
| TOMMY_API void tommy_arrayof_done | ( | tommy_arrayof * | array | ) |
Deinitializes the array.
| TOMMY_API void tommy_arrayof_grow | ( | tommy_arrayof * | 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.
| array | Array to grow. |
| size | New size of the array. |
| void * tommy_arrayof_ref | ( | tommy_arrayof * | 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_arrayof_grow().
| array | Array to reference. |
| pos | Position of the element. |
| tommy_size_t tommy_arrayof_size | ( | tommy_arrayof * | array | ) |
Gets the initialized size of the array.
| array | Array to query. |
| TOMMY_API tommy_size_t tommy_arrayof_memory_usage | ( | tommy_arrayof * | array | ) |
Gets the size of allocated memory.
| array | Array to query. |