rvMemoryBlock_s* m_prev; // previous block in memory (next is implied by address of memory block plus distToNextBlock)
dword m_dwordDistToNextBlock : NUM_MEMORY_BLOCK_SIZE_BITS; // distance, in double words (4 bytes), from the first byte of this rvMemoryBlock_s header to the first byte of the next rvMemoryBlock_s header
dword m_tag : NUM_TAG_BITS; // bits used to tag the type of allocation and state of memory block (zero for free)
// GetDistToNextBlock
//
// returns: the distance to the next block, in bytes
// ResetValues(); do this in the Init() call instead (due to the fact that other constructors could call rvHeap::Init() before this constructor is called)
}
// ~rvHeap
//
// destructor
rvHeap::~rvHeap( )
{
Shutdown();
}
// Init
//
// initializes this heap for use within the given arena, and with the given size limit that it can grow to
//
// heapArena heap arena that this heap is associated with
// maxHeapSizeBytes maximum number of bytes this heap can grow to
// flags flags describing the capabilities of this heap
m_heapRangeBytes = m_maxHeapSizeBytes + PAGE_SIZE; // add a page at the beginning for zero-length allocations (not part of page table and is never committed)
assert(sizeof(dword) == 4); // assumed by following code
// frees all the allocations from this heap (and decommits all pages)
void rvHeap::FreeAll( )
{
if ( NULL == m_baseAddress )
{
return;
}
EnterHeapCriticalSection( );
VirtualFree( m_heapStorageStart, m_maxHeapSizeBytes, MEM_DECOMMIT ); // this decommits all of the physical pages (frees physical memory), but leaves the virtual address range reserved to this heap