Proud::CFastHeap Class Referenceabstract

Public Types

enum  { DefaultAccelBlockSizeLimit = 2048 }

Public Member Functions

virtual void * Alloc (size_t size)=0
virtual void * Realloc (void *ptr, size_t size)=0
virtual void Free (void *ptr)=0
virtual int DebugCheckConsistency ()=0

Static Public Member Functions

static PROUD_API CFastHeapNew (size_t AccelBlockSizeLimit=DefaultAccelBlockSizeLimit, const CFastHeapSettings &settings=CFastHeapSettings())
static void AssureValidBlock (void *block)

Detailed Description

Though this allocation class allocates heap alloc with high speed but there are some restrictions.



  • High allocation speed


  • The instance allocated by this allocator must be destructed before main() terminates. In other words, must be carefu when set this as global variable.
  • A certain size or bigger cannot be accelerated.
  • This leaves some unused memory when used for a long time since this is memory pool way. Therefore, this can be used only when there are needs to perform frequent allocation/destruction.

Member Function Documentation

virtual void* Proud::CFastHeap::Alloc ( size_t  size)
pure virtual

Allocate the memory. The allocated memory may be adjusted by Realloc or Free.

sizeSize of the memory to be allocated.
static void Proud::CFastHeap::AssureValidBlock ( void *  block)

If block is not created by fast heap then it will either produce an error window or cause a crash.

virtual void Proud::CFastHeap::Free ( void *  ptr)
pure virtual

Clear the memory that was allocated.

ptrPointer of the memory that was allocated.
static PROUD_API CFastHeap* Proud::CFastHeap::New ( size_t  AccelBlockSizeLimit = DefaultAccelBlockSizeLimit,
const CFastHeapSettings settings = CFastHeapSettings() 

Creates CFastHeap object

AccelBlockSizeLimitWhenever allocating memory block bigger than this value, this allocates a usual memory block that does not follow lookaside allocator. Bigger this value becomes, occupies more memory but also increased chance of high speed heap allocation probability. (But if it is too bug then it lowers performance due to page fault cost.)
pHeapIn order to let this Fast Heap use other Heap that is not previously created by ProudNet, CMemoryHeap object pointer must be entered in here. But, this class does not automatically remove CMemoryHeap. If NULL is entered in here then uses previously created Heap by ProudNet.
safeModePlease refer CLookasideAllocator.New()
debugSafetyCheckCritSecfor debugging use. Only valid when safeMode=false Whenever access to this fast heap, must check if critical section pointed by debugSafetyCheckCritSec is in its locked status by current thread, if not locked then this alarms that error occurs.
virtual void* Proud::CFastHeap::Realloc ( void *  ptr,
size_t  size 
pure virtual

Reallocate the memory. As reallocated memory may have its position switched, you must refer the returned pointer value.

ptrMemory pointer to be reallocated.
sizeMemory size to be reallocated.