blockpool
["Little Useful Bits" Library]

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

Data Structures

struct  _lub_blockpool
struct  _lub_blockpool_stats

Typedefs

typedef _lub_blockpool_block lub_blockpool_block_t
typedef _lub_blockpool lub_blockpool_t
typedef _lub_blockpool_stats lub_blockpool_stats_t

Functions

void lub_blockpool_init (lub_blockpool_t *blockpool, void *memory, size_t blocksize, unsigned blockcount)
void * lub_blockpool_alloc (lub_blockpool_t *blockpool)
void lub_blockpool_free (lub_blockpool_t *blockpool, void *block)
void lub_blockpool__get_stats (lub_blockpool_t *instance, lub_blockpool_stats_t *stats)

Detailed Description

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

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

This allocator uses block 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.

The client is responsible for providing the memory to be managed.

Author:
Graeme McKerrell
Date:
Created On : Fri Jan 23 12:50:18 2004
Version:
TESTED

Typedef Documentation

typedef struct _lub_blockpool_stats lub_blockpool_stats_t

This type defines the statistics available for each blockpool.

typedef struct _lub_blockpool lub_blockpool_t

This type represents a "blockpool" instance.


Function Documentation

void lub_blockpool__get_stats ( lub_blockpool_t instance,
lub_blockpool_stats_t stats 
)

This operation fills out a statistics structure with the details for the specified blockpool.

Precondition:
  • none
Postcondition:
  • the results filled out are a snapshot of the statistics as the time of the call.
Parameters:
instance  The instance on which to operate
stats  A client provided structure to fill out with the blockpool details

void* lub_blockpool_alloc ( lub_blockpool_t blockpool  ) 

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

Precondition:
The blockpool 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 "blockpool" is uninitialised.
Parameters:
blockpool  the "blockpool" instance to invoke this operation upon

void lub_blockpool_free ( lub_blockpool_t blockpool,
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:
blockpool  the "blockpool" instance to invoke this operation upon
block  the "block" to release back to the pool

void lub_blockpool_init ( lub_blockpool_t blockpool,
void *  memory,
size_t  blocksize,
unsigned  blockcount 
)

This operation initialises an instance of a blockpool.

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:
blockpool  the "blockpool" instance to initialise.
memory  the memory to be managed.
blocksize  The size in bytes of each block.
blockcount  The number of blocks to be managed. NB the client is responsible for ensuring that (blocksize x blockcount) bytes of memory are available for use.


Generated on Tue Apr 29 13:41:08 2008 for CLISH by  doxygen 1.5.1