Nebula
|
#include <poolarrayallocator.h>
Allocates small memory blocks from an array of fixed-size memory pools.
Bigger allocation go directly through to a heap. Note that when freeing a memory block, there are 2 options: one with providing the size of the memory block (which is probably a bit faster) and one conventional without providing the size.
Public Member Functions | |
PoolArrayAllocator () | |
constructor | |
~PoolArrayAllocator () | |
destructor | |
void | Setup (const char *name, Memory::HeapType heapType, uint poolSizes[NumPools]) |
setup the pool allocator, name must be a static string! | |
void * | Alloc (SizeT size) |
allocate a block of memory from the pool | |
void | Free (void *ptr, SizeT size) |
free a block of memory from the pool array with original block size | |
void | Free (void *ptr) |
free a block of memory from the pool array | |
const MemoryPool & | GetMemoryPool (IndexT index) const |
access to memory pool at pool index (for debugging) | |
Static Public Attributes | |
static const SizeT | NumPools = 8 |
number of pools | |
Private Attributes | |
Memory::HeapType | heapType |
const char * | name |
MemoryPool | memoryPools [NumPools] |
Memory::PoolArrayAllocator::PoolArrayAllocator | ( | ) |
constructor
Memory::PoolArrayAllocator::~PoolArrayAllocator | ( | ) |
destructor
void * Memory::PoolArrayAllocator::Alloc | ( | SizeT | size | ) |
allocate a block of memory from the pool
void Memory::PoolArrayAllocator::Free | ( | void * | ptr | ) |
free a block of memory from the pool array
This is the slower version to free a memory block.
Worst case is, that the allocator needs to check each memory pool whether the pointer is owned by the pool.
void Memory::PoolArrayAllocator::Free | ( | void * | ptr, |
SizeT | size ) |
free a block of memory from the pool array with original block size
This is the faster version to free a memory block, if the caller knows the size of the memory block we can compute the memory pool index whithout asking each pool whether the pointer is owned by this pool.
const MemoryPool & Memory::PoolArrayAllocator::GetMemoryPool | ( | IndexT | index | ) | const |
access to memory pool at pool index (for debugging)
void Memory::PoolArrayAllocator::Setup | ( | const char * | name, |
Memory::HeapType | heapType, | ||
uint | poolSizes[NumPools] ) |
setup the pool allocator, name must be a static string!
|
private |
|
private |
|
private |
|
static |
number of pools