ndn-lite
Macros | Functions
Memory Array

Memory pool manages pseudo memory blocks in a static memory array. More...

Collaboration diagram for Memory Array:

Macros

#define NDN_MEMORY_POOL_RESERVE_SIZE(block_size, block_count)   (sizeof(void*) * ((block_count) + 1) + (block_size) * (block_count))
 The required memory to initialize a memory pool. More...
 

Functions

void ndn_memory_pool_init (void *pool, size_t block_size, size_t block_count)
 Initialize a memory array pool for block_count elements in the size of block_size. More...
 
uint8_t * ndn_memory_pool_alloc (void *pool)
 Allocate a new block in size block_size. More...
 
int ndn_memory_pool_free (void *pool, void *ptr)
 Free allocated memory block. More...
 

Detailed Description

Memory pool manages pseudo memory blocks in a static memory array.

All memory blocks should be in fixed size.

Macro Definition Documentation

◆ NDN_MEMORY_POOL_RESERVE_SIZE

#define NDN_MEMORY_POOL_RESERVE_SIZE (   block_size,
  block_count 
)    (sizeof(void*) * ((block_count) + 1) + (block_size) * (block_count))

The required memory to initialize a memory pool.

Parameters
block_sizeSize of a block.
block_countLength of the array.

Function Documentation

◆ ndn_memory_pool_alloc()

uint8_t* ndn_memory_pool_alloc ( void *  pool)

Allocate a new block in size block_size.

Parameters
[in,out]poolThe pool address of memory array.
Returns
A pointer to the allocated block. NULL for insufficient memory.

◆ ndn_memory_pool_free()

int ndn_memory_pool_free ( void *  pool,
void *  ptr 
)

Free allocated memory block.

Parameters
[in,out]poolThe pool address of memory array.
[in,out]ptrPointer to the block to be freed.
Return values
0Succeeded.
-1Illegal input.
Note
Memory at ptr is changed, so it's marked [in, out]

◆ ndn_memory_pool_init()

void ndn_memory_pool_init ( void *  pool,
size_t  block_size,
size_t  block_count 
)

Initialize a memory array pool for block_count elements in the size of block_size.

Precondition
(block_size * block_count + sizeof(void*) * (block_count+1)) bytes needed.
Parameters
[in,out]poolThe base address of memory array.
[in]block_sizeSize of a block.
[in]block_countLength of the array.
Note
No check for (base != NULL) .