#include <GameMemory.h>
Public Member Functions | |
| DynamicMemoryAllocator * | getNextDmaInList () |
| 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 |
| MemoryPool * | getNthDmaMemoryPool (Int i) const |
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.
| DynamicMemoryAllocator::DynamicMemoryAllocator | ( | ) |
init the DMA to safe values.
Definition at line 2004 of file GameMemory.cpp.
| DynamicMemoryAllocator::~DynamicMemoryAllocator | ( | ) |
destroy the dma and its subpools.
Definition at line 2056 of file GameMemory.cpp.
| 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.
| 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.
| 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.
| 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.
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.
|
inline |
Definition at line 455 of file GameMemory.h.
|
inline |
return next dma in linked list
Definition at line 772 of file GameMemory.h.
|
inline |
Definition at line 456 of file GameMemory.h.
| 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.
| 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.
| 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.