Nebula
Loading...
Searching...
No Matches
Base::GenericMemoryPool Class Reference

#include <genericmemorypool.h>

Detailed Description

A simple thread-safe memory pool.

Memory pool items are 16-byte aligned.

FIXME:

  • debug: overwrite memory blocks with pattern
  • debug: check for double-free
  • debug: check for mem-leaks
  • debug: list memory pools in Debug HTML page!

Public Member Functions

 GenericMemoryPool ()
 constructor
 
 ~GenericMemoryPool ()
 destructor
 
void Setup (Memory::HeapType heapType, uint blockSize, uint numBlocks)
 setup the memory pool
 
void * Alloc ()
 allocate a block from the pool (NOTE: returns 0 if pool exhausted!)
 
void Free (void *ptr)
 deallocate a block from the pool
 
bool IsPoolBlock (void *ptr) const
 return true if block is owned by this pool
 
uint GetNumBlocks () const
 get number of allocated blocks in pool
 
uint GetBlockSize () const
 get block size
 
uint GetAlignedBlockSize () const
 get aligned block size
 
uint GetPoolSize () const
 get pool size
 

Static Public Member Functions

static uint ComputeAlignedBlockSize (uint blockSize)
 compute the actual block size including alignment and management data
 

Private Attributes

Memory::HeapType heapType
 
uint blockSize
 
uint alignedBlockSize
 
uint poolSize
 
uint numBlocks
 
Threading::SafeQueue< ubyte * > freeList
 
ubytepoolStart
 
ubytepoolEnd
 

Static Private Attributes

static const uint FreeBlockPattern = 0xFE
 get current allocation count
 
static const uint NewBlockPattern = 0xFD
 
static const int BlockAlign = 16
 

Constructor & Destructor Documentation

◆ GenericMemoryPool()

Base::GenericMemoryPool::GenericMemoryPool ( )

constructor

◆ ~GenericMemoryPool()

Base::GenericMemoryPool::~GenericMemoryPool ( )

destructor

Member Function Documentation

◆ Alloc()

void * Base::GenericMemoryPool::Alloc ( )

allocate a block from the pool (NOTE: returns 0 if pool exhausted!)

◆ ComputeAlignedBlockSize()

uint Base::GenericMemoryPool::ComputeAlignedBlockSize ( uint blockSize)
inlinestatic

compute the actual block size including alignment and management data

◆ Free()

void Base::GenericMemoryPool::Free ( void * ptr)

deallocate a block from the pool

◆ GetAlignedBlockSize()

uint Base::GenericMemoryPool::GetAlignedBlockSize ( ) const
inline

get aligned block size

◆ GetBlockSize()

uint Base::GenericMemoryPool::GetBlockSize ( ) const
inline

get block size

◆ GetNumBlocks()

uint Base::GenericMemoryPool::GetNumBlocks ( ) const
inline

get number of allocated blocks in pool

◆ GetPoolSize()

uint Base::GenericMemoryPool::GetPoolSize ( ) const
inline

get pool size

◆ IsPoolBlock()

bool Base::GenericMemoryPool::IsPoolBlock ( void * ptr) const
inline

return true if block is owned by this pool

◆ Setup()

void Base::GenericMemoryPool::Setup ( Memory::HeapType heapType,
uint blockSize,
uint numBlocks )

setup the memory pool

Member Data Documentation

◆ alignedBlockSize

uint Base::GenericMemoryPool::alignedBlockSize
private

◆ BlockAlign

const int Base::GenericMemoryPool::BlockAlign = 16
staticprivate

◆ blockSize

uint Base::GenericMemoryPool::blockSize
private

◆ FreeBlockPattern

const uint Base::GenericMemoryPool::FreeBlockPattern = 0xFE
staticprivate

get current allocation count

◆ freeList

Threading::SafeQueue<ubyte*> Base::GenericMemoryPool::freeList
private

◆ heapType

Memory::HeapType Base::GenericMemoryPool::heapType
private

◆ NewBlockPattern

const uint Base::GenericMemoryPool::NewBlockPattern = 0xFD
staticprivate

◆ numBlocks

uint Base::GenericMemoryPool::numBlocks
private

◆ poolEnd

ubyte* Base::GenericMemoryPool::poolEnd
private

◆ poolSize

uint Base::GenericMemoryPool::poolSize
private

◆ poolStart

ubyte* Base::GenericMemoryPool::poolStart
private

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