br_pool
Note that currently, there is no automatic contraction of Pools, nor are there functions to achieve this (with the current implementation it would have a relatively high processing overhead). Therefore, it may be wise to destroy Pools when possible, if they have irregular or sporadic use, or memory is at a premium.
typedef
pool.h
for precise declaration and ordering)
br_pool_block * free Linked list of unused blocks
br_uint_32 block_size Size of each item
br_uint_32 chunk_size Number of blocks to increase pool by
int mem_type Memory class of blocks
BrAllocatorSet()
100
.
Members
Primary
This is a pointer to the next available block of memory (of size br_pool_block * free
block_size
). When freed, blocks are cast as br_pool_block
303 and inserted at the head of the list to keep track of them. An allocation simply removes the item at the head from the list. It may then be initialised as required.
br_uint_32 block_size
sizeof(br_pool_block)
, if not, memory corruption will ensue. This is typically 4 bytes, but given that pools are intended for larger structures, this is not a significant restriction. See BrPoolAllocate()
301
.
br_uint_32 chunk_size
uint mem_type
A pointer to the relevant pool.
Returns a pointer to the allocated block, or NULL if unsuccessful.
A pointer to the relevant pool.
A pointer to the block to deallocate.
A pointer to the pool to be emptied.
Effectively this sets
The size of each block, in bytes. Minimum value is 1, though note that this size will be rounded up to the next multiple of a suitable alignment factor, typically 8 (
The number of blocks to allocate each time the pool becomes full. The value should be between 1 and say, 10% of the maximum number of blocks allocated at any one time. Naturally, there is a compromise between saving processing overhead for each memory allocation (only when the pool grows), and saving memory overhead in terms of average unused blocks.
Memory type. More than one pool may be created for a particular memory class.
Returns a pointer to the new pool, or
A pointer to the pool to be deallocated.
Operations
Description:
Allocate a block from a pool. If the pool is full, it will expand as necessary.BrPoolBlockAllocate()
void* BrPoolBlockAllocate(br_pool* pool)
br_pool * pool
void *
Description:
Deallocate a block from a pool.BrPoolBlockFree()
void BrPoolBlockFree(br_pool* pool, void* b)
br_pool * pool
void * b
Description:
Mark all blocks in a pool as unused.BrPoolEmpty()
void BrPoolEmpty(br_pool* pool)
br_pool * pool
Copy/Assign
Do not copy. Access & Maintenance
No members should be modified. The structure will be maintained until the pool is freed using BrPoolFree()
302. No additional maintenance required.
Referencing & Lifetime
Do not reference a copy. Ensure that references to a pool descriptor do not outlast the pool. Initialisation
Initialisation is performed by BrPoolAllocate()
301.
free
to NULL
, block_size
to the specified value (aligned appropriately), chunk_size
to the specified value, and mem_type
to the specified value. Construction & Destruction
Memory pool structures should be constructed by BrPoolAllocate()
301, as this will allocate the pool descriptors from the pool resource class. Some Pool functions depend on this.
Description:
Create a new block pool.BrPoolAllocate()
br_pool* BrPoolAllocate(int block_size, int chunk_size, br_uint_8 mem_type)
int block_size
BR_POOL_ALIGN+1
). Pools are not intended for simple data structures.int chunk_size
br_uint_8 mem_type
br_pool *
NULL
if it could not be created.
Description:
Deallocate an entire pool, thereby losing any blocks it may contain.BrPoolFree()
void BrPoolFree(br_pool* pool)
br_pool * pool
Supplementary
Given that Pools are registered in the "POOL"
resource class, the resource class supplementary functions are available.
Generated with CERN WebMaker