Honeycomb
0.1
Component-Model Framework
|
Memory pool. More...
#include <Pool.h>
Public Member Functions | |
MemPool (const vector< tuple< szt, szt >> &buckets, const Id &id=idnull, szt align=alignof(double)) | |
void * | alloc (szt size, uint8 align=1, const char *srcFile=nullptr, int srcLine=0) |
Allocate a size bytes block of memory at byte boundary align . alignment must be a power of two. More... | |
void | free (void *ptr_) |
Free a memory block allocated from the pool. More... | |
szt | allocBytes () const |
Calc total bytes allocated by pool. More... | |
szt | usedBytes () const |
Calc total bytes used in pool. More... | |
szt | freeBytes () const |
Calc total bytes free in pool. More... | |
void | validate () const |
Ensure that all used/free blocks are valid (check signatures) More... | |
String | printStats () const |
Print statistics about pool. More... | |
String | printUsed () const |
Print all used blocks. More... | |
const Id & | id () const |
Friends | |
template<class > | |
class | lockfree::FreeList |
Memory pool.
The pool primarily allocates from buckets of fixed size blocks, if there's no block big enough to hold the allocation then the pool falls back on the system heap allocator.
The pool will initially allocate memory for all its buckets in one contiguous chunk. Buckets automatically expand but their chunks are not contiguous across expansions.
The pool is thread-safe and its buckets are lock-free, although locks may be encountered during allocation when bucket expansion is required.
On platforms with a 64-bit atomic swap the pool supports 2^24 blocks per bucket. Alloc complexity is O(log B) where B is the number of buckets. Free complexity is O(1).
honey::MemPool::MemPool | ( | const vector< tuple< szt, szt >> & | buckets, |
const Id & | id = idnull , |
||
szt | align = alignof(double) |
||
) |
buckets | A vector of tuples (blockSize, blockCount). |
id | display id for debugging Buckets of blocks available to the pool for allocation. |
align | Alignment byte boundary for all blocks. Alignment must be a power of two. |
void * honey::MemPool::alloc | ( | szt | size, |
uint8 | align = 1 , |
||
const char * | srcFile = nullptr , |
||
int | srcLine = 0 |
||
) |
Allocate a size
bytes block of memory at byte boundary align
. alignment must be a power of two.
szt honey::MemPool::allocBytes | ( | ) | const |
Calc total bytes allocated by pool.
void honey::MemPool::free | ( | void * | ptr_ | ) |
Free a memory block allocated from the pool.
|
inline |
Calc total bytes free in pool.
|
inline |
String honey::MemPool::printStats | ( | ) | const |
Print statistics about pool.
String honey::MemPool::printUsed | ( | ) | const |
Print all used blocks.
szt honey::MemPool::usedBytes | ( | ) | const |
Calc total bytes used in pool.
void honey::MemPool::validate | ( | ) | const |
Ensure that all used/free blocks are valid (check signatures)
|
friend |