Main Page | Modules | Directories | File List

Memory pool manipulation functions for fixed size object


Functions

int ememoa_mempool_fixed_init (struct ememoa_mempool_fixed_s *memory, unsigned int object_size, unsigned int preallocated_item_pot, unsigned int options, const struct ememoa_mempool_desc_s *desc)
 Initializes a memory pool structure for later use.
int ememoa_mempool_fixed_clean (struct ememoa_mempool_fixed_s *memory)
 Destroys all allocated objects of the memory pool and uninitialize them.
void * ememoa_mempool_fixed_pop_object (struct ememoa_mempool_fixed_s *memory)
 Pops a new object out of the memory pool.
int ememoa_mempool_fixed_free_all_objects (struct ememoa_mempool_fixed_s *memory)
 Destroys all allocated object of the memory pool.
int ememoa_mempool_fixed_push_object (struct ememoa_mempool_fixed_s *memory, void *ptr)
 Push back an object in the memory pool.
int ememoa_mempool_fixed_garbage_collect (struct ememoa_mempool_fixed_s *memory)
 Collects all the empty pool and resizes the Mempool accordingly.
int ememoa_mempool_fixed_walk_over (struct ememoa_mempool_fixed_s *memory, ememoa_fctl fctl, void *data)
 Executes fctl on all allocated data in the pool.

Function Documentation

int ememoa_mempool_fixed_clean struct ememoa_mempool_fixed_s *  memory  ) 
 

Destroys all allocated objects of the memory pool and uninitialize them.

The memory pool is unusable after the call of this function.

The following example code demonstrates how to ensure that a given memory pool has been successfully destroyed

 if (ememoa_mempool_fixed_clean (&test_pool))
 {
    fprintf (stderr, "ERROR: Memory pool destruction failed.\n");
    exit (-1);
 }

Parameters:
memory Pointer to a valid address of a memory pool. If NULL is passed the call will fail. If the address was already a initialized memory pool, bad things will happen to your program.
Returns:
Will return 0 if successfully cleaned.

int ememoa_mempool_fixed_free_all_objects struct ememoa_mempool_fixed_s *  memory  ) 
 

Destroys all allocated object of the memory pool.

The memory pool is still usable after the call of this function.

Parameters:
memory Pointer to a valid address of a memory pool. If NULL is passed, the call will fail. If the address was already a initialized memory pool, bad things will happen to your program.
Returns:
Will return 0 if successfully cleaned.

int ememoa_mempool_fixed_garbage_collect struct ememoa_mempool_fixed_s *  memory  ) 
 

Collects all the empty pool and resizes the Mempool accordingly.

The following example code demonstrates how to ensure that a given Mempool gives back some memory or die.

Parameters:
memory Pointer to a valid address of a memory pool. If memory is not a valid memory pool, bad things will happen.
Returns:
Will return 0 if some pools were freed.

int ememoa_mempool_fixed_init struct ememoa_mempool_fixed_s *  memory,
unsigned int  object_size,
unsigned int  preallocated_item_pot,
unsigned int  options,
const struct ememoa_mempool_desc_s *  desc
 

Initializes a memory pool structure for later use.

The following example code demonstrates how to ensure that the given memory pool has been successfully initialized.

 struct ememoa_mempool_fixed_s  test_pool;

 if (ememoa_mempool_fixed_init (&test_pool, sizeof (int), 10, NULL))
 {
    fprintf (stderr, "ERROR: Memory pool initialization failed\n");
    exit (-1);
 }

Parameters:
memory Pointer to a valid address of a memory pool. If NULL is passed, the call will fail. If the address was already a initialized memory pool, bad things will happen to your program.
object_size Size of the object that will be provided by the new pool. If 0 is passed, the call will fail.
preallocated_item_pot Number of items tobe pre-allocated by the pool. They are exprimed in power of two (10 will mean 1024 elements per pool). If 0 is passed the call will fail. Using 1 will really be stupid.
options This parameter will give you the possibility to take into account the exact pattern usage of the memory pool. Right now, only EMEMOA_THREAD_PROTECTION is supported, but futur improvement could use this facilty too.
desc Pointer to a valid description for this new pool. If NULL is passed, you will not be able to see the content of the memory for debug purpose.
Returns:
Will return 0 if the initialization of the memory pool is successful.

void* ememoa_mempool_fixed_pop_object struct ememoa_mempool_fixed_s *  memory  ) 
 

Pops a new object out of the memory pool.

The following example code demonstrate how to ensure that a pointer has been successfully retrieved from the memory pool.

   object_s *new_object = ememoa_mempool_fixed_pop_object (&mempool_of_object);

   if (new_object == NULL)
   {
    fprintf (stderr, "ERROR: %s", ememoa_mempool_error2string (mempool_of_object.last_error_code));
    exit (-1);
   }

Parameters:
memory Pointer to a valid address of a memory pool. If Pointer is not a valid memory pool, bad things will happens to your program.
Returns:
Will return NULL if it was impossible to allocate any data. Check memory->last_error_code and ememoa_mempool_error2string to know why.

int ememoa_mempool_fixed_push_object struct ememoa_mempool_fixed_s *  memory,
void *  ptr
 

Push back an object in the memory pool.

The following example code demonstrates how to ensure that a given pointer has been successfully given back to his memory pool.

   if (ememoa_mempool_fixed_push_object (&mempool_of_object, new_object))
   {
    fprintf (stderr, "ERROR: %s", ememoa_mempool_error2string (mempool_of_object.last_error_code));
    exit (-1);
   }

Parameters:
memory Pointer to a valid address of a memory pool. If memory is not a valid memory pool, bad things will happen.
ptr Pointer to object that belongs to memory mempool.
Returns:
Will return 0 if it was successfully pushed back to the memory pool. If not, check memory->last_error_code and ememoa_mempool_error2string to know why.

int ememoa_mempool_fixed_walk_over struct ememoa_mempool_fixed_s *  memory,
ememoa_fctl  fctl,
void *  data
 

Executes fctl on all allocated data in the pool.

If the execution of fctl returns something else than 0, then the walk ends and returns the error code provided by fctl.

Parameters:
memory Pointer to a valid address of a memory pool. If memory is not a valid memory pool, bad things will happen.
fctl Function pointer that must be run on all allocated objects.
data Pointer that will be passed as is to each call to fctl.
Returns:
Will return 0 if the run walked over all allocated objects.


Generated on Tue Mar 21 15:19:24 2006 for Ememoa by  doxygen 1.4.4