Main Page | Modules | Data Structures | Data Fields

Memory pool


Detailed Description

Memory pool allocator for objects of same size. This interface offers an allocator peak_mem_pool_new() which is O(1) except in some rare cases when the pool is growing (at worst log2(n) times for n allocations). However, if you know its size in advance, you can precise it in the peak_mem_pool creation method peak_mem_pool_create(). You can create as many memory pools you want as interface and implementation are object oriented (like most of peak stuffs).


Typedefs

typedef __peak_mem_pool * peak_mem_pool
 Opaque mem_pool pointer type.


Functions

peak_mem_pool peak_mem_pool_create (int object_size, int log_size)
 Create a mem_pool object.

void * peak_mem_pool_new (peak_mem_pool pool)
 Allocate an object in constant time.

void peak_mem_pool_delete (peak_mem_pool pool, void *ptr)
 Deallocate an object in constant time.

int peak_mem_pool_get_used_count (peak_mem_pool pool)
 Statistics: get used pointers count.

int peak_mem_pool_get_free_count (peak_mem_pool pool)
 Statistics: get free pointers count.

int peak_mem_pool_get_size (peak_mem_pool pool)
 Statistics: get total pointers count.


Function Documentation

peak_mem_pool peak_mem_pool_create int  object_size,
int  log_size
 

Create a mem_pool object.

Parameters:
object_size Size of each object in the memory pool. This cannot be changed later. It's commonly sizeof(struct your_object_structure).
log_size Log base 2 of the initial size of memory pool. Use 0 if you don't know, it will use the minimum.
Returns:
A new allocated peak_mem_pool reference or NULL if the operation failed.

void peak_mem_pool_delete peak_mem_pool  pool,
void *  ptr
 

Deallocate an object in constant time.

This method is guaranted O(1) but in rare case it might free a chunk of memory.

Parameters:
pool The memory pool reference.
ptr The pointer to a memory space to deallocate. This pointer must have been previously provided by peak_mem_pool_new().

int peak_mem_pool_get_free_count peak_mem_pool  pool  ) 
 

Statistics: get free pointers count.

This method is guaranted O(1).

Parameters:
pool The memory pool reference.
Returns:
Number of pointer currently unused (free for allocation).

int peak_mem_pool_get_size peak_mem_pool  pool  ) 
 

Statistics: get total pointers count.

This method is guaranted O(1).

Parameters:
pool The memory pool reference.
Returns:
Size of all pointers really allocated by the memory pool. It grows automatically when no more free pointers are available, and also might eventually decrease if needed.

int peak_mem_pool_get_used_count peak_mem_pool  pool  ) 
 

Statistics: get used pointers count.

This method is guaranted O(1).

Parameters:
pool The memory pool reference.
Returns:
Number of pointer currently in use (allocated).

void* peak_mem_pool_new peak_mem_pool  pool  ) 
 

Allocate an object in constant time.

This method is guaranted O(1) almost all the time, but in rare case it might allocate a chunk of memory to let the memory pool grow.

Parameters:
pool The memory pool reference.
Returns:
A pointer to object_size bytes of memory. The allocated space is suitably aligned for storage of any common type of object. Please consult libpeak's compile time options to enable storage of special object like Altivec's vector (which needs 16-bytes align). Also please note the returned memory is NOT normally initialized to zero bytes.


Generated on Thu Jan 8 18:16:24 2004 for the PEAK Library by doxygen     SourceForge.net Logo