KMemoryReusePool Class Reference

#include <kmemory.h>
Inheritance diagram for KMemoryReusePool:
Inheritance graph
[legend]

List of all members.


Detailed Description

A pool of memory blocks of arbitrary size.

Definition at line 164 of file kmemory.h.


Public Member Functions

  KMemoryReusePool (size_t pSizeRange=1024 *128, int pStrideShift=2, int pAlignmentShift=0, size_t pTotalAllocatedMax=0)
virtual  ~KMemoryReusePool ()
virtual void  Purge ()
virtual void *  Malloc (size_t pSize)
virtual void *  Calloc (size_t pCount, size_t pSize)
virtual void *  Realloc (void *pData, size_t pSize)
virtual void  Free (void *pData)

Protected Member Functions

bool  SizeFitsInPool (size_t pSize) const
bool  PoolIsFull () const
kUChar  ComputeAlignmentOffset (void *pBuffer)
void *  AssignHeaderAndReturnBlock (void *pBuffer, size_t pBufferSize)
size_t  GetBufferAndSize (void *pBlock, void *&pBuffer)

Static Protected Member Functions

static int  ComputeRightShiftRemainder (int pStrideShift)
static size_t  GetHeaderSize ()

Protected Attributes

KMpMutex *  mLock
  Critical section on our pool (maintained by pointer only to not force a dependency on windows.h at large).
void **  mBuffer
  Our array of free lists, of size mBufferSize.
size_t const  mSizeRange
  Maximum alloc size.
size_t const  mBufferSize
  mSizeRange >> mStrideShift.
int const  mStrideShift
  Divider for mSizeRange.
int const  mStrideRemainder
  A mask of the remainder of a right shift done with mStrideShift.
int const  mAlignmentShift
  Multiplier, to specify an alignment in bytes.
size_t const  mTotalAllocatedMax
  Maximum total amount of memory handed out or managed by this pool (past this point, normal allocs are done).
size_t  mTotalAllocated
  The total amount of memory handed out or managed by this pool.
size_t  mTotalBlocks
  The total number of blocks handed out or managed by this pool.

Classes

struct   KBlockHeader

Constructor & Destructor Documentation

KMemoryReusePool ( size_t  pSizeRange = 1024 *128,
int  pStrideShift = 2,
int  pAlignmentShift = 0,
size_t  pTotalAllocatedMax = 0  
) [explicit]

virtual ~KMemoryReusePool (  )  [virtual]

Member Function Documentation

virtual void Purge (  )  [virtual]

Reimplemented from KMemoryAllocator.

virtual void* Malloc ( size_t  pSize  )  [virtual]

Reimplemented from KMemoryAllocator.

virtual void* Calloc ( size_t  pCount,
size_t  pSize  
) [virtual]

Reimplemented from KMemoryAllocator.

virtual void* Realloc ( void *  pData,
size_t  pSize  
) [virtual]

Reimplemented from KMemoryAllocator.

virtual void Free ( void *  pData  )  [virtual]

Reimplemented from KMemoryAllocator.

bool SizeFitsInPool ( size_t  pSize  )  const [inline, protected]

Definition at line 181 of file kmemory.h.

bool PoolIsFull (  )  const [inline, protected]

Definition at line 182 of file kmemory.h.

kUChar ComputeAlignmentOffset ( void *  pBuffer  )  [protected]

static int ComputeRightShiftRemainder ( int  pStrideShift  )  [static, protected]

void* AssignHeaderAndReturnBlock ( void *  pBuffer,
size_t  pBufferSize  
) [protected]

size_t GetBufferAndSize ( void *  pBlock,
void *&  pBuffer  
) [protected]

static size_t GetHeaderSize (  )  [static, protected]

Member Data Documentation

KMpMutex* mLock [protected]

Critical section on our pool (maintained by pointer only to not force a dependency on windows.h at large).

Definition at line 201 of file kmemory.h.

void* * mBuffer [protected]

Our array of free lists, of size mBufferSize.

Definition at line 202 of file kmemory.h.

size_t const mSizeRange [protected]

Maximum alloc size.

Definition at line 203 of file kmemory.h.

size_t const mBufferSize [protected]

mSizeRange >> mStrideShift.

Definition at line 204 of file kmemory.h.

int const mStrideShift [protected]

Divider for mSizeRange.

Definition at line 205 of file kmemory.h.

int const mStrideRemainder [protected]

A mask of the remainder of a right shift done with mStrideShift.

Definition at line 206 of file kmemory.h.

int const mAlignmentShift [protected]

Multiplier, to specify an alignment in bytes.

Definition at line 207 of file kmemory.h.

size_t const mTotalAllocatedMax [protected]

Maximum total amount of memory handed out or managed by this pool (past this point, normal allocs are done).

Definition at line 208 of file kmemory.h.

size_t mTotalAllocated [protected]

The total amount of memory handed out or managed by this pool.

Definition at line 209 of file kmemory.h.

size_t mTotalBlocks [protected]

The total number of blocks handed out or managed by this pool.

Definition at line 210 of file kmemory.h.

KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool
KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool KMemoryReusePool