Nebula
Loading...
Searching...
No Matches
Win32::Win32MemoryPool Class Reference

#include <win32memorypool.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

 Win32MemoryPool ()
 constructor
 
 ~Win32MemoryPool ()
 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
 
SLIST_HEADER listHead
 
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

◆ Win32MemoryPool()

Win32::Win32MemoryPool::Win32MemoryPool ( )

constructor

◆ ~Win32MemoryPool()

Win32::Win32MemoryPool::~Win32MemoryPool ( )

destructor

Member Function Documentation

◆ Alloc()

void * Win32::Win32MemoryPool::Alloc ( )

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

◆ ComputeAlignedBlockSize()

uint Win32::Win32MemoryPool::ComputeAlignedBlockSize ( uint blockSize)
inlinestatic

compute the actual block size including alignment and management data

◆ Free()

void Win32::Win32MemoryPool::Free ( void * ptr)

deallocate a block from the pool

◆ GetAlignedBlockSize()

uint Win32::Win32MemoryPool::GetAlignedBlockSize ( ) const
inline

get aligned block size

◆ GetBlockSize()

uint Win32::Win32MemoryPool::GetBlockSize ( ) const
inline

get block size

◆ GetNumBlocks()

uint Win32::Win32MemoryPool::GetNumBlocks ( ) const
inline

get number of allocated blocks in pool

◆ GetPoolSize()

uint Win32::Win32MemoryPool::GetPoolSize ( ) const
inline

get pool size

◆ IsPoolBlock()

bool Win32::Win32MemoryPool::IsPoolBlock ( void * ptr) const
inline

return true if block is owned by this pool

◆ Setup()

void Win32::Win32MemoryPool::Setup ( Memory::HeapType heapType,
uint blockSize,
uint numBlocks )

setup the memory pool

NOTE: name must be a static string!

Member Data Documentation

◆ alignedBlockSize

uint Win32::Win32MemoryPool::alignedBlockSize
private

◆ BlockAlign

const int Win32::Win32MemoryPool::BlockAlign = 16
staticprivate

◆ blockSize

uint Win32::Win32MemoryPool::blockSize
private

◆ FreeBlockPattern

const uint Win32::Win32MemoryPool::FreeBlockPattern = 0xFE
staticprivate

get current allocation count

◆ heapType

Memory::HeapType Win32::Win32MemoryPool::heapType
private

◆ listHead

SLIST_HEADER Win32::Win32MemoryPool::listHead
private

◆ NewBlockPattern

const uint Win32::Win32MemoryPool::NewBlockPattern = 0xFD
staticprivate

◆ numBlocks

uint Win32::Win32MemoryPool::numBlocks
private

◆ poolEnd

ubyte* Win32::Win32MemoryPool::poolEnd
private

◆ poolSize

uint Win32::Win32MemoryPool::poolSize
private

◆ poolStart

ubyte* Win32::Win32MemoryPool::poolStart
private

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