1#ifndef MEM_POOL_H 2#define MEM_POOL_H 3 4struct mp_block { 5struct mp_block *next_block; 6char*next_free; 7char*end; 8uintmax_t space[FLEX_ARRAY];/* more */ 9}; 10 11struct mem_pool { 12struct mp_block *mp_block; 13 14/* 15 * The amount of available memory to grow the pool by. 16 * This size does not include the overhead for the mp_block. 17 */ 18size_t block_alloc; 19 20/* The total amount of memory allocated by the pool. */ 21size_t pool_alloc; 22}; 23 24/* 25 * Initialize mem_pool with specified initial size. 26 */ 27voidmem_pool_init(struct mem_pool **mem_pool,size_t initial_size); 28 29/* 30 * Discard a memory pool and free all the memory it is responsible for. 31 */ 32voidmem_pool_discard(struct mem_pool *mem_pool); 33 34/* 35 * Alloc memory from the mem_pool. 36 */ 37void*mem_pool_alloc(struct mem_pool *pool,size_t len); 38 39/* 40 * Allocate and zero memory from the memory pool. 41 */ 42void*mem_pool_calloc(struct mem_pool *pool,size_t count,size_t size); 43 44#endif