Data Structures | Defines | Typedefs | Functions

tommyds/tommyarrayblk.h File Reference

Dynamic array based on blocks of fixed size. More...

Go to the source code of this file.

Data Structures

struct  tommy_arrayblk_struct
 Array container type. More...

Defines

#define TOMMY_ARRAYBLK_SIZE   (4 * 1024)
 Elements for each block.

Typedefs

typedef struct
tommy_arrayblk_struct 
tommy_arrayblk
 Array container type.

Functions

void tommy_arrayblk_init (tommy_arrayblk *array)
 Initializes the array.
void tommy_arrayblk_done (tommy_arrayblk *array)
 Deinitializes the array.
void tommy_arrayblk_grow (tommy_arrayblk *array, tommy_count_t size)
 Grows the size up to the specified value.
void ** tommy_arrayblk_ref (tommy_arrayblk *array, tommy_count_t pos)
 Gets a reference of the element at the specified position.
void tommy_arrayblk_set (tommy_arrayblk *array, tommy_count_t pos, void *element)
 Sets the element at the specified position.
void * tommy_arrayblk_get (tommy_arrayblk *array, tommy_count_t pos)
 Gets the element at the specified position.
void tommy_arrayblk_insert (tommy_arrayblk *array, void *element)
 Grows and inserts a new element at the end of the array.
tommy_count_t tommy_arrayblk_size (tommy_arrayblk *array)
 Gets the initialized size of the array.
tommy_size_t tommy_arrayblk_memory_usage (tommy_arrayblk *array)
 Gets the size of allocated memory.

Detailed Description

Dynamic array based on blocks of fixed size.

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

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

Allocated blocks are always of the same fixed size of 4 Ki pointers.


Define Documentation

#define TOMMY_ARRAYBLK_SIZE   (4 * 1024)

Elements for each block.


Typedef Documentation

Array container type.

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

Function Documentation

void tommy_arrayblk_init ( tommy_arrayblk array)

Initializes the array.

void tommy_arrayblk_done ( tommy_arrayblk array)

Deinitializes the array.

void tommy_arrayblk_grow ( tommy_arrayblk 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_arrayblk_ref ( tommy_arrayblk 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_arrayblk_grow().

void tommy_arrayblk_set ( tommy_arrayblk 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_arrayblk_grow().

void* tommy_arrayblk_get ( tommy_arrayblk 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_arrayblk_grow().

void tommy_arrayblk_insert ( tommy_arrayblk array,
void *  element 
)

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

tommy_count_t tommy_arrayblk_size ( tommy_arrayblk array)

Gets the initialized size of the array.

tommy_size_t tommy_arrayblk_memory_usage ( tommy_arrayblk array)

Gets the size of allocated memory.