ndn-lite
memory-pool.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-2019 Zhiyi Zhang, Xinyu Ma
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v3.0. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #ifndef memory_pool_h
10 #define memory_pool_h
11 
12 #include <stdint.h>
13 #include <stddef.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
35 #define NDN_MEMORY_POOL_RESERVE_SIZE(block_size, block_count) \
36  (sizeof(void*) * ((block_count) + 1) + (block_size) * (block_count))
37 
46 void
47 ndn_memory_pool_init(void* pool, size_t block_size, size_t block_count);
48 
54 uint8_t*
55 ndn_memory_pool_alloc(void* pool);
56 
65 int
66 ndn_memory_pool_free(void* pool, void* ptr);
67 
70 #ifdef __cplusplus
71 }
72 #endif
73 
74 #endif /* memory_pool_h */
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.
Definition: memory-pool.c:23
int ndn_memory_pool_free(void *pool, void *ptr)
Free allocated memory block.
Definition: memory-pool.c:55
uint8_t * ndn_memory_pool_alloc(void *pool)
Allocate a new block in size block_size.
Definition: memory-pool.c:42