memory array allocator

memory array allocator More...

Detailed Description

memory array allocator

pseudo dynamic allocation in static memory arrays

Author
Tobias Heider heide.nosp@m.rt@n.nosp@m.m.ifi.nosp@m..lmu.nosp@m..de

Data Structures

struct  memarray_t
 Memory pool. More...
 

Functions

void memarray_init (memarray_t *mem, void *data, size_t size, size_t num)
 Initialize memarray pool with free list. More...
 
void * memarray_alloc (memarray_t *mem)
 Allocate memory chunk in memarray pool. More...
 
void memarray_free (memarray_t *mem, void *ptr)
 Free memory chunk in memarray pool. More...
 

Function Documentation

◆ memarray_alloc()

void* memarray_alloc ( memarray_t mem)

Allocate memory chunk in memarray pool.

Precondition
mem != NULL
Parameters
[in,out]memmemarray pool to allocate block in
Returns
pointer to allocated structure, if enough memory was available
NULL, on failure

◆ memarray_free()

void memarray_free ( memarray_t mem,
void *  ptr 
)

Free memory chunk in memarray pool.

Precondition
mem != NULL
ptr != NULL
Parameters
[in,out]memmemarray pool to free block in
[in]ptrpointer to memarray chunk

◆ memarray_init()

void memarray_init ( memarray_t mem,
void *  data,
size_t  size,
size_t  num 
)

Initialize memarray pool with free list.

Precondition
mem != NULL
data != NULL
size >= sizeof(void*)
num != 0
Parameters
[in,out]memmemarray pool to initialize
[in]datapointer to user-allocated data
[in]sizesize of a single element in data
[in]numnumber of elements in data