Honeycomb  0.1
Component-Model Framework
Classes | Public Member Functions | Friends | List of all members
honey::MemPool Class Reference

Memory pool. More...

#include <Pool.h>

Inheritance diagram for honey::MemPool:
Inheritance graph
[legend]
Collaboration diagram for honey::MemPool:
Collaboration graph
[legend]

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 Idid () const
 

Friends

template<class >
class lockfree::FreeList
 

Detailed Description

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).

Constructor & Destructor Documentation

honey::MemPool::MemPool ( const vector< tuple< szt, szt >> &  buckets,
const Id id = idnull,
szt  align = alignof(double) 
)
Parameters
bucketsA vector of tuples (blockSize, blockCount).
iddisplay id for debugging Buckets of blocks available to the pool for allocation.
alignAlignment byte boundary for all blocks. Alignment must be a power of two.

Member Function Documentation

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.

szt honey::MemPool::freeBytes ( ) const
inline

Calc total bytes free in pool.

const Id& honey::MemPool::id ( ) const
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)

Friends And Related Function Documentation

template<class >
friend class lockfree::FreeList
friend

The documentation for this class was generated from the following files: