MLib Alpha 1 API Reference

MLib Alpha 1 API Reference

Memory Pools

an MLib memory pool is a fast memory allocator for fixed-size blocks.

note that the reason why memory pools are so fast is due to two facts: first, blocks are allocated in batches from the heap. Second, once allocated, a block will never be released to the heap until the pool itself is destroyed.

never forget that modern implementations of the standard "malloc" and "free" functions are already very fast. Using memory pools is really handy when you want to absolutely reduce fragmentation, and need to perform _lots_ of consecutive allocs and frees..

the MLib uses memory pools to manage list nodes, hash nodes, tree nodes and other frequently used fixed-sized objects..


M_MemoryPool


  typedef struct M_MemoryPoolRec_*   M_MemoryPool;

handle to a memory pool object. A memory pool is used to allocate and release memory blocks of the same size extremely rapidly. This is useful to manage things like list nodes, hash nodes, etc..



m_memory_pool_find


  MLIB_API(M_MemoryPool)
  m_memory_pool_find( M_Memory  memory,
                      M_Size    element_size );

find a memory pool that stores memory blocks of a given size


input
memory

memory manager handle

element_size

element size for the memory pool

return

memory pool handle, can be NULL


m_memory_pool_alloc


  MLIB_API(M_Pointer)
  m_memory_pool_alloc( M_MemoryPool  pool,
                       M_Size        size );

allocate a block from a given memory pool


intput
pool

memory pool handle

size

size of memory block. this parameter is only used for debugging purpose, and must _match_ the value used to create or find the memory pool (e.g. the "element_size" parameter of the m_memory_pool_find call used to retrieve the memory pool handle).

return

new block (it is not zero-filled !!)


m_memory_pool_free


  MLIB_API(void)
  m_memory_pool_free( M_Pointer     data,
                      M_MemoryPool  pool );

free a given memory block that was previously allocated with m_memory_pool_alloc .


intput
data

memory block address

pool

memory pool handle


generated on Tue Oct 09 23:59:46 2001