TaPAS  0.2
Typedefs | Functions
ccl-pool.h File Reference

A by-packet allocator. More...

#include <ccl/ccl-common.h>
#include <ccl/ccl-log.h>

Go to the source code of this file.

Typedefs

typedef struct ccl_pool_st ccl_pool
 Abstract type of a Pool.
 

Functions

ccl_poolccl_pool_create (const char *poolname, size_t object_size, int nb_elements)
 Creates a pool named by poolname that allocates packets of nb_elements objects each one having a size of object_size bytes. More...
 
void ccl_pool_delete (ccl_pool *pool)
 Deletion of pool. More...
 
void * ccl_pool_alloc (ccl_pool *pool)
 Allocates a new object. More...
 
void ccl_pool_release (ccl_pool *pool, void *ptr)
 Releases the block pointed by ptr. More...
 
void ccl_pool_collect (ccl_pool *pool)
 Tries to collect completely free packets. More...
 
void ccl_pool_display_info (ccl_log_type lt, ccl_pool *pool)
 Display statictics about pool. More...
 
void ccl_pools_collect (void)
 Collect packets in all pools. More...
 
void ccl_pools_display_info (ccl_log_type lt)
 Display statistics about all pools. More...
 

Detailed Description

A by-packet allocator.

Definition in file ccl-pool.h.

Function Documentation

void* ccl_pool_alloc ( ccl_pool pool)

Allocates a new object.

The function looks for a free object in one of the already allocated packets. If such object exists then its address is returned. Else, a new packet is allocated and the address of a fresh object is returned.

The area returned by the function is not filled with zero.

Parameters
poolthe pool
Precondition
pool != NULL
Returns
a pointer to a new object
void ccl_pool_collect ( ccl_pool pool)

Tries to collect completely free packets.

This function looks for packets whose all objects are free. The memory allocated to such packet is removed.

Parameters
poolthe pool
Precondition
ptr != NULL
ccl_pool* ccl_pool_create ( const char *  poolname,
size_t  object_size,
int  nb_elements 
)

Creates a pool named by poolname that allocates packets of nb_elements objects each one having a size of object_size bytes.

Parameters
poolnamea string displayed with statistics about pools
object_sizethe size (in bytes) of objects stored in the pool
nb_elementsthe number of objects allocated by packet
Precondition
object_size >= sizeof (void *)
nb_elements > 0
Returns
a pool handling objects of size object_size
void ccl_pool_delete ( ccl_pool pool)

Deletion of pool.

The function releases all resources allocated to this pool. All packets of objects are also freed thus references to objects are no longer valid after this function.

Parameters
poolthe pool to delete
Precondition
pool != NULL
void ccl_pool_display_info ( ccl_log_type  lt,
ccl_pool pool 
)

Display statictics about pool.

Parameters
ltthe stream on which statistics are displayed
poolthe pool
Precondition
pool != NULL
void ccl_pool_release ( ccl_pool pool,
void *  ptr 
)

Releases the block pointed by ptr.

The function puts the block pointed by ptr into the list of free objects of the pool pool.

Parameters
poolthe pool
ptrthe address of an object to collect
Precondition
pool != NULL
ptr != NULL
void ccl_pools_collect ( void  )

Collect packets in all pools.

This function simply applies ccl_pool_collect to all existing pools.

void ccl_pools_display_info ( ccl_log_type  lt)

Display statistics about all pools.

This function simply applies ccl_pool_display_info to all existing pools.

Parameters
ltthe stream on which statistics are displayed