Data Structures | Macros | Typedefs | Functions
tommyarray.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_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

void tommy_array_init (tommy_array *array)
 Initializes the array. More...
 
void tommy_array_done (tommy_array *array)
 Deinitializes the array. More...
 
void tommy_array_grow (tommy_array *array, tommy_count_t size)
 Grows the size up to the specified value. More...
 
void ** tommy_array_ref (tommy_array *array, tommy_count_t pos)
 Gets a reference of the element at the specified position. More...
 
void tommy_array_set (tommy_array *array, tommy_count_t pos, void *element)
 Sets the element at the specified position. More...
 
void * tommy_array_get (tommy_array *array, tommy_count_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_count_t tommy_array_size (tommy_array *array)
 Gets the initialized size of the array. More...
 
tommy_size_t tommy_array_memory_usage (tommy_array *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.

The grow operation involves an allocation of a new array segment, without reallocating the already used memory, and then not increasing the heap fragmentation. This also implies that the address of the stored elements never change.

Allocated segments grow in size exponentially.

Macro Definition Documentation

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

Array container type.

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

Function Documentation

void tommy_array_init ( tommy_array array)

Initializes the array.

void tommy_array_done ( tommy_array array)

Deinitializes the array.

void tommy_array_grow ( tommy_array 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_array_ref ( tommy_array 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_array_grow().

void tommy_array_set ( tommy_array 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_array_grow().

void* tommy_array_get ( tommy_array 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_array_grow().

void tommy_array_insert ( tommy_array array,
void *  element 
)

Grows and inserts a new element at the end of the array.

tommy_count_t tommy_array_size ( tommy_array array)

Gets the initialized size of the array.

tommy_size_t tommy_array_memory_usage ( tommy_array array)

Gets the size of allocated memory.