Data Structures | Macros | Typedefs | Functions
tommyarrayof.h File Reference

Dynamic array based on segments of exponential 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

void tommy_arrayof_init (tommy_arrayof *array, tommy_size_t element_size)
 Initializes the array. More...
 
void tommy_arrayof_done (tommy_arrayof *array)
 Deinitializes the array. More...
 
void tommy_arrayof_grow (tommy_arrayof *array, tommy_count_t size)
 Grows the size up to the specified value. More...
 
void * tommy_arrayof_ref (tommy_arrayof *array, tommy_count_t pos)
 Gets a reference of the element at the specified position. More...
 
tommy_count_t tommy_arrayof_size (tommy_arrayof *array)
 Gets the initialized size of the array. More...
 
tommy_size_t tommy_arrayof_memory_usage (tommy_arrayof *array)
 Gets the size of allocated memory. More...
 

Detailed Description

Dynamic array based on segments of exponential growing size.

This array is able to grow dynamically upon request, without any reallocation.

This is very similar at 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.

Macro Definition Documentation

#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 Documentation

Array container type.

Note
Don't use internal fields directly, but access the container only using functions.

Function Documentation

void tommy_arrayof_init ( tommy_arrayof array,
tommy_size_t  element_size 
)

Initializes the array.

Parameters
element_sizeSize in byte of the element to store in the array.
void tommy_arrayof_done ( tommy_arrayof array)

Deinitializes the array.

void tommy_arrayof_grow ( tommy_arrayof 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_arrayof_ref ( tommy_arrayof 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_arrayof_grow().

tommy_count_t tommy_arrayof_size ( tommy_arrayof array)

Gets the initialized size of the array.

tommy_size_t tommy_arrayof_memory_usage ( tommy_arrayof array)

Gets the size of allocated memory.