CLISH  0.7.3
Data Structures | Typedefs | Functions

This interface provides a dynamic facility to manage the allocation and deallocation of fixed sized blocks of memory. More...

Data Structures

struct  _lub_dblockpool
 

Typedefs

typedef struct _lub_dblockpool lub_dblockpool_t
 

Functions

void lub_dblockpool_init (lub_dblockpool_t *instance, size_t blocksize, unsigned chunksize, unsigned max_chunks)
 
void lub_dblockpool_fini (lub_dblockpool_t *instance)
 
void * lub_dblockpool_alloc (lub_dblockpool_t *instance)
 
void lub_dblockpool_free (lub_dblockpool_t *instance, void *block)
 

Detailed Description

This interface provides a dynamic facility to manage the allocation and deallocation of fixed sized blocks of memory.

It dynamically allocates chunks of memory each of which is used as a "blockpool". This dynamic memory is taken from the standard heap via "malloc()".

This type of memory manager is very fast and doesn't suffer from any memory fragmentation problems.

This allocator can reuse blocks in the order in which they are freed, this is significant for some applications where you don't want to re-use a particular freed block too soon. e.g. hardware timing limits on re-use.

Author
Graeme McKerrell
Date
Created On : Fri Feb 24 14:50:18 2005
Version
TESTED

Typedef Documentation

This type represents a "dblockpool" instance.

Function Documentation

void* lub_dblockpool_alloc ( lub_dblockpool_t instance)

This operation allocates a "block" of memory from a "dblockpool"

Precondition
The dblockpool must have been initialised.
Returns
A pointer to a "block" of memory, or NULL if there is none left for allocation.
Postcondition
The behaviour is undefined if the "dblockpool" is uninitialised.
Parameters
instancethe "dblockpool" instance to operate on
void lub_dblockpool_fini ( lub_dblockpool_t instance)

This operation finalises an instance of a dblockpool.

Precondition
'instance' must have been initialised first.
Postcondition
All the dynamic memory allocated will be released.
Parameters
instancethe "dblockpool" instance to finalise.
void lub_dblockpool_free ( lub_dblockpool_t instance,
void *  block 
)

This operation de-allocates a "block" of memory back into a "blockpool"

Precondition
The specified block must have been previously allocated using lub_blockpool_alloc()
Postcondition
The de-allocated block become available for subsequent lub_blockpool_alloc() requests.
Parameters
instancethe "blockpool" instance to invoke this operation upon
blockthe "block" to release back to the pool
void lub_dblockpool_init ( lub_dblockpool_t instance,
size_t  blocksize,
unsigned  chunksize,
unsigned  max_chunks 
)

This operation initialises an instance of a dblockpool.

Precondition
'blocksize' must be an multiple of 'sizeof(void *)'. (If the client declares a structure for the block this should be handled automatically by the compiler)
Postcondition
If the size constraint is not met an assert will fire.
Following initialisation the allocation of memory can be performed.
Parameters
instancethe "dblockpool" instance to initialise.
blocksizeThe size in bytes of each block.
chunksizeThe number of blocks to be managed in a chunk.
max_chunksThe maximum number of chunks to be allocated. (a value of zero means unlimited...)