Main Page | Modules | Directories | File List

Memory pool manipulation functions for variable size objects


Functions

int ememoa_mempool_unknown_size_init (struct ememoa_mempool_unknown_size_s *memory, unsigned int map_items_count, const unsigned int *map_size_count, unsigned int options, const struct ememoa_mempool_desc_s *desc)
 Initializes a memory pool structure for later use.
int ememoa_mempool_unknown_size_clean (struct ememoa_mempool_unknown_size_s *memory)
 Destroys all allocated objects of the memory pool and uninitialize it.
int ememoa_mempool_unknown_size_free_all_objects (struct ememoa_mempool_unknown_size_s *memory)
 Destroys all allocated object of the memory pool.
int ememoa_mempool_unknown_size_push_object (struct ememoa_mempool_unknown_size_s *memory, void *ptr)
 Push back an object in the memory pool.
void * ememoa_mempool_unknown_size_pop_object (struct ememoa_mempool_unknown_size_s *memory, unsigned int size)
 Pops a new object out of the memory pool.
int ememoa_mempool_unknown_size_garbage_collect (struct ememoa_mempool_unknown_size_s *memory)
 Collects all the empty pool and resize the Mempool accordingly.
int ememoa_mempool_unknown_size_walk_over (struct ememoa_mempool_unknown_size_s *memory, ememoa_fctl fctl, void *data)
 Execute fctl on all allocated data in the pool.

Function Documentation

int ememoa_mempool_unknown_size_clean struct ememoa_mempool_unknown_size_s *  memory  ) 
 

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

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

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

 if (ememoa_mempool_unknown_size_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_unknown_size_free_all_objects struct ememoa_mempool_unknown_size_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_unknown_size_garbage_collect struct ememoa_mempool_unknown_size_s *  memory  ) 
 

Collects all the empty pool and resize the Mempool accordingly.

The following example code demonstrate how to ensure that a given Mempool give some memory back 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_unknown_size_init struct ememoa_mempool_unknown_size_s *  memory,
unsigned int  map_items_count,
const unsigned int *  map_size_count,
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_unknown_size_s   test_pool;

 if (ememoa_mempool_unknown_size_init (&test_pool, sizeof(default_map_size_count)/(sizeof(unsigned int) * 2), default_map_size_count, 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 an initialized memory pool, bad things will happen to your program.
map_items_count Number of fixed size pools to create.
map_size_count Array of element describing fixed pools used by this memory pool. Odd row for size, even row for preallocated items. Take a look at default_map_size_count.
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 contents of the memory for debug purpose.
Returns:
Will return 0 if succeed in the initialization of the memory pool.

void* ememoa_mempool_unknown_size_pop_object struct ememoa_mempool_unknown_size_s *  memory,
unsigned int  size
 

Pops a new object out of the memory pool.

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

   object_s *new_object = ememoa_mempool_unknown_size_pop_object (&mempool_of_object, 100);

   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_unknown_size_push_object struct ememoa_mempool_unknown_size_s *  memory,
void *  ptr
 

Push back an object in the memory pool.

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

   if (ememoa_mempool_unknown_size_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 an object belonging to memory mempool.
Returns:
Will return 0 if it was successfully pushed back to the memory pool. Else, check memory->last_error_code and ememoa_mempool_error2string to know why.

int ememoa_mempool_unknown_size_walk_over struct ememoa_mempool_unknown_size_s *  memory,
ememoa_fctl  fctl,
void *  data
 

Execute fctl on all allocated data in the pool.

If the execution of fctl 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