uBlink  0.0.1
TheBlinkProtocol
blink_pool

Description

A linear memory allocator for uBlink modules.

Example Workflow

A blink_pool must be initialised (or reinitialised) before use:

uint8_t heap[1024U];
struct blink_pool pool;
(void)BLINK_PoolInit(&pool, heap, sizeof(heap));

Allocate a word aligned block:

long *memory = (long *)BLINK_Pool_calloc(&pool, 42U);
// a null pointer means the pool is exhausted
assert(memory != NULL);
// note that BLINK_Pool_calloc interface will return zeroed memory
assert(*memory == 0);
*memory = 42;

Find out how much memory can still be allocated:

printf("free space: %u\n", BLINK_Pool_getFreeSpace(&pool));

Functions

blink_pool_t BLINK_Pool_init (struct blink_pool *self, uint8_t *heap, size_t size)
 This function will initialise a blink_pool_static structure. More...
 
void * BLINK_Pool_calloc (blink_pool_t self, size_t size)
 Allocate word aligned memory from the pool. More...
 
size_t BLINK_Pool_getFreeSpace (blink_pool_t self)
 Discover how much free memory is left in the pool. More...
 

Data Structures

Typedefs

typedef struct blink_poolblink_pool_t
 This type shall be used by uBlink modules to refer to initialised pools.
 

Data Structure Documentation

struct blink_pool
Examples:
tc_blink_pool.c.
Data Fields
uint8_t * heap pointer to assigned heap
size_t pos free memory offset
size_t size size of heap in bytes

Function Documentation

void* BLINK_Pool_calloc ( blink_pool_t  self,
size_t  size 
)

Allocate word aligned memory from the pool.

Note
memory shall be set to zero at allocation time
Parameters
[in]selfinitialsed pool
[in]sizenumber of bytes to allocate
Returns
pointer to allocated memory
Return values
NULLinsufficient free memory
Examples:
tc_blink_pool.c.
size_t BLINK_Pool_getFreeSpace ( blink_pool_t  self)

Discover how much free memory is left in the pool.

Parameters
[in]selfinitialised pool
Returns
free space in bytes
Examples:
tc_blink_pool.c.
blink_pool_t BLINK_Pool_init ( struct blink_pool self,
uint8_t *  heap,
size_t  size 
)

This function will initialise a blink_pool_static structure.

Parameters
[in]self
[in]heapA pointer to word aligned memory block that will be used as the heap.
[in]sizeThe size of the heap memory block in bytes.
Returns
intialised blink_pool_static
Examples:
tc_blink_pool.c.