Very simple allocator for use with pointer_list
.
More...
#include <pointer_list.h>
Classes | |
struct | chunk |
One memory allocation chunk. | |
Public Member Functions | |
allocator (size_t nelt, size_t nblock, unsigned long end_mask, unsigned long end_offs) | |
Constructor. | |
~allocator () | |
Destructor. Deletes all blocks from this allocator. | |
list_block * | allocate () |
Allocate a new block. | |
size_t | nelt () const |
size_t | nchunks () const |
Return the current number of allocated chunks. | |
bool | at_end (const void *p) const |
Test if P is pointing at the end-pointer of a block. |
Very simple allocator for use with pointer_list
.
We allocate large chunks and divide them up into list_block's
. We don't support deleting individual elements; instead, everything is deleted when the allocator is. The chunks are chained together to allow for this.
The total size of a block should be a power of two, and blocks must be aligned to this boundary.
CxxUtils::pointer_list_base::allocator::allocator | ( | size_t | nelt, | |
size_t | nblock, | |||
unsigned long | end_mask, | |||
unsigned long | end_offs | |||
) |
Constructor.
nelt | Number of pointers per block (excluding the end pointer). Must be one less than a power of two. | |
nblock | Number of blocks to allocate per chunk. | |
end_mask | Mask to use for end-of-block test. | |
end_offs | Offset to use for end-of-block test. | |
nelt | Number of pointers per block. (excluding the end pointer). | |
nblock | Number of blocks to allocate per chunk. | |
end_mask | Mask to use for end-of-block test. | |
end_offs | Offset to use for end-of-block test. |
bool CxxUtils::pointer_list_base::allocator::at_end | ( | const void * | p | ) | const [inline] |
Test if P is pointing at the end-pointer of a block.
Test to see if we're looking at the end of a block.
p | The pointer to test. |
size_t CxxUtils::pointer_list_base::allocator::nchunks | ( | ) | const [inline] |
Return the current number of allocated chunks.
Current number of allocated chunks.
size_t CxxUtils::pointer_list_base::allocator::nelt | ( | ) | const [inline] |
Return the number of pointers per block (excluding the end-pointer).