Memory pool manages pseudo memory blocks in a static memory array.
More...
|
| #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...
|
| |
Memory pool manages pseudo memory blocks in a static memory array.
All memory blocks should be in fixed size.
◆ 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_size | Size of a block. |
| block_count | Length of the array. |
◆ ndn_memory_pool_alloc()
| uint8_t* ndn_memory_pool_alloc |
( |
void * |
pool | ) |
|
Allocate a new block in size block_size.
- Parameters
-
| [in,out] | pool | The 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] | pool | The pool address of memory array. |
| [in,out] | ptr | Pointer to the block to be freed. |
- Return values
-
| 0 | Succeeded. |
| -1 | Illegal 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] | pool | The base address of memory array. |
| [in] | block_size | Size of a block. |
| [in] | block_count | Length of the array. |
- Note
- No check for
(base != NULL) .