28static struct _MemoryBlock *
 
   29_memory_pool_create_block(
const MemoryPool *pool)
 
   33    struct _MemoryBlock *block;
 
   35    if(!(block = (
struct _MemoryBlock *)malloc(
sizeof(
struct _MemoryBlock))))
 
   53static struct _MemoryPtrBlock *
 
   54_memory_pool_create_ptr_block(
const MemoryPool *pool)
 
   58    struct _MemoryPtrBlock *block;
 
   60    if(!(block = (
struct _MemoryPtrBlock *)malloc(
sizeof(
struct _MemoryPtrBlock))))
 
   66    if(!(block->items = (
void **)malloc(pool->
block_size * 
sizeof(
void *))))
 
   79_memory_pool_try_get_detached_item(
MemoryPool *pool)
 
   93            struct _MemoryPtrBlock *pblock = pool->
free_block;
 
  104_memory_pool_try_get_current_item(
const MemoryPool *pool)
 
  106    assert(pool != NULL);
 
  119_memory_pool_get_item_from_new_block(
MemoryPool *pool)
 
  121    assert(pool != NULL);
 
  123    struct _MemoryBlock *block = _memory_pool_create_block(pool);
 
  124    block->next = pool->
block;
 
  135_memory_pool_alloc(
Pool *alloc)
 
  139    void *item = _memory_pool_try_get_detached_item(pool);
 
  143        item = _memory_pool_try_get_current_item(pool);
 
  148        item = _memory_pool_get_item_from_new_block(pool);
 
  155_memory_pool_free(
Pool *alloc, 
void *item)
 
  158    struct _MemoryPtrBlock *cur;
 
  162        pool->
free_block = cur = _memory_pool_create_ptr_block(pool);
 
  166        cur = _memory_pool_create_ptr_block(pool);
 
  171    cur->
items[cur->offset++] = item;
 
  179    assert(item_size > 1);
 
  180    assert(block_size > 1);
 
  181    assert(block_size < SIZE_MAX / item_size);
 
  182    assert(block_size < SIZE_MAX / 
sizeof(
void *));
 
  193    pool->
block = _memory_pool_create_block(pool);
 
  195    ((
Pool *)pool)->alloc = _memory_pool_alloc;
 
  196    ((
Pool *)pool)->free = _memory_pool_free;
 
 
  204    struct _MemoryBlock *iter;
 
  205    struct _MemoryPtrBlock *piter;
 
  207    assert(pool != NULL);
 
  214        struct _MemoryBlock *block;
 
  227        struct _MemoryPtrBlock *pblock;
 
 
void memory_pool_destroy(MemoryPool *pool)
MemoryPool * memory_pool_new(size_t item_size, size_t block_size)
Allocate memory blocks of same sizes.
struct _MemoryBlock * next
struct _MemoryPtrBlock * next
struct MemoryPool::_MemoryPtrBlock * free_block
First pointer block.
struct MemoryPool::_MemoryBlock * block
First memory block.
This memory pool allocates blocks of memory and grows automatically.
Allocate groups of equal-sized chunks of memory.