Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
DynamicMemoryAllocator Class Reference

#include <GameMemory.h>

Public Member Functions

DynamicMemoryAllocatorgetNextDmaInList ()
 return next dma in linked list
 
void addToList (DynamicMemoryAllocator **pHead)
 add this dma to the list
 
void removeFromList (DynamicMemoryAllocator **pHead)
 remove this dma from the list
 
 DynamicMemoryAllocator ()
 
void init (MemoryPoolFactory *factory, Int numSubPools, const PoolInitRec pParms[])
 initialize the dma. pass 0/null for numSubPool/parms to get some reasonable default subpools.
 
 ~DynamicMemoryAllocator ()
 
void * allocateBytesImplementation (Int numBytes DECLARE_LITERALSTRING_ARG2)
 allocate bytes from this pool. (don't call directly; use allocateBytes() macro)
 
void * allocateBytesDoNotZeroImplementation (Int numBytes DECLARE_LITERALSTRING_ARG2)
 like allocateBytesImplementation, but zeroes the memory before returning
 
void freeBytes (void *pMem)
 free the bytes. (assumes allocated by this dma.)
 
Int getActualAllocationSize (Int numBytes)
 
void reset ()
 destroy all allocations performed by this DMA.
 
Int getDmaMemoryPoolCount () const
 
MemoryPoolgetNthDmaMemoryPool (Int i) const
 

Detailed Description

The DynamicMemoryAllocator class is used to handle unpredictably-sized allocation requests. It basically allocates a number of (private) MemoryPools, then routes request to the smallest-size pool that will satisfy the request. (Requests too large for any of the pool are routed to the system memory allocator.) You should normally use this in place of malloc/free or (global) new/delete.

Definition at line 387 of file GameMemory.h.

Constructor & Destructor Documentation

◆ DynamicMemoryAllocator()

DynamicMemoryAllocator::DynamicMemoryAllocator ( )

init the DMA to safe values.

Definition at line 2004 of file GameMemory.cpp.

◆ ~DynamicMemoryAllocator()

DynamicMemoryAllocator::~DynamicMemoryAllocator ( )

destroy the dma and its subpools.

Todo
this may cause double-destruction of the subpools – test & fix

Definition at line 2056 of file GameMemory.cpp.

Member Function Documentation

◆ addToList()

void DynamicMemoryAllocator::addToList ( DynamicMemoryAllocator ** pHead)

add this dma to the list

add this DMA to the factory's list of dmas.

Definition at line 2093 of file GameMemory.cpp.

◆ allocateBytesDoNotZeroImplementation()

void * DynamicMemoryAllocator::allocateBytesDoNotZeroImplementation ( Int numBytes DECLARE_LITERALSTRING_ARG2)

like allocateBytesImplementation, but zeroes the memory before returning

allocate a chunk-o-bytes from this DMA and return it, but don't bother zeroing out the block. if unable to allocate, throw ERROR_OUT_OF_MEMORY. this function will never return null.

added code to make sure we're on a DWord boundary, throw exception if not

Definition at line 2162 of file GameMemory.cpp.

◆ allocateBytesImplementation()

void * DynamicMemoryAllocator::allocateBytesImplementation ( Int numBytes DECLARE_LITERALSTRING_ARG2)

allocate bytes from this pool. (don't call directly; use allocateBytes() macro)

allocate a chunk-o-bytes from this DMA and return it, and zero out the contents first. if unable to allocate, throw ERROR_OUT_OF_MEMORY. this function will never return null.

Definition at line 2264 of file GameMemory.cpp.

◆ freeBytes()

void DynamicMemoryAllocator::freeBytes ( void * pBlockPtr)

free the bytes. (assumes allocated by this dma.)

free a chunk-o-bytes allocated by this dma. it's ok to pass null.

Definition at line 2275 of file GameMemory.cpp.

◆ getActualAllocationSize()

Int DynamicMemoryAllocator::getActualAllocationSize ( Int numBytes)

return the actual number of bytes that would be allocated if you tried to allocate the given size. (It will generally be slightly larger than you request.) This lets you use extra space if you're gonna get it anyway... The idea is that you will call this before doing a memory allocation, to see if you got any extra "bonus" space.

Definition at line 2365 of file GameMemory.cpp.

◆ getDmaMemoryPoolCount()

Int DynamicMemoryAllocator::getDmaMemoryPoolCount ( ) const
inline

Definition at line 455 of file GameMemory.h.

◆ getNextDmaInList()

DynamicMemoryAllocator * DynamicMemoryAllocator::getNextDmaInList ( )
inline

return next dma in linked list

Definition at line 772 of file GameMemory.h.

◆ getNthDmaMemoryPool()

MemoryPool * DynamicMemoryAllocator::getNthDmaMemoryPool ( Int i) const
inline

Definition at line 456 of file GameMemory.h.

◆ init()

void DynamicMemoryAllocator::init ( MemoryPoolFactory * factory,
Int numSubPools,
const PoolInitRec pParms[] )

initialize the dma. pass 0/null for numSubPool/parms to get some reasonable default subpools.

Initialize the dma and its subpools.

Definition at line 2019 of file GameMemory.cpp.

◆ removeFromList()

void DynamicMemoryAllocator::removeFromList ( DynamicMemoryAllocator ** pHead)

remove this dma from the list

remove this DMA from the factory's list of dmas.

Definition at line 2103 of file GameMemory.cpp.

◆ reset()

void DynamicMemoryAllocator::reset ( )

destroy all allocations performed by this DMA.

throw away everything in the DMA, but keep the DMA itself valid.

Definition at line 2375 of file GameMemory.cpp.


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