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

#include <GameMemory.h>

Public Member Functions

MemoryPoolgetNextPoolInList ()
 return next pool in linked list
 
void addToList (MemoryPool **pHead)
 add this pool to head of the linked list
 
void removeFromList (MemoryPool **pHead)
 remove this pool from the linked list
 
 MemoryPool ()
 
void init (MemoryPoolFactory *factory, const char *poolName, Int allocationSize, Int initialAllocationCount, Int overflowAllocationCount)
 initialize the given memory pool.
 
 ~MemoryPool ()
 
void * allocateBlockImplementation (DECLARE_LITERALSTRING_ARG1)
 allocate a block from this pool. (don't call directly; use allocateBlock() macro)
 
void * allocateBlockDoNotZeroImplementation (DECLARE_LITERALSTRING_ARG1)
 same as allocateBlockImplementation, but memory returned is not zeroed
 
void freeBlock (void *pMem)
 free the block. it is OK to pass null.
 
MemoryPoolFactorygetOwningFactory ()
 return the factory that created (and thus owns) this pool.
 
const char * getPoolName ()
 return the name of this pool. the result is a literal string and must not be freed.
 
Int getAllocationSize ()
 return the block allocation size of this pool.
 
Int getFreeBlockCount ()
 return the number of free (available) blocks in this pool.
 
Int getUsedBlockCount ()
 return the number of blocks in use in this pool.
 
Int getTotalBlockCount ()
 return the total number of blocks in this pool. [ == getFreeBlockCount() + getUsedBlockCount() ]
 
Int getPeakBlockCount ()
 return the high-water mark for getUsedBlockCount()
 
Int getInitialBlockCount ()
 return the initial allocation count for this pool
 
Int countBlobsInPool ()
 
Int releaseEmpties ()
 if this pool has any empty blobs, return them to the system.
 
void reset ()
 destroy all blocks and blobs in this pool.
 

Detailed Description

A MemoryPool provides a way to efficiently allocate objects of the same (or similar) size. We allocate large a large chunk of memory (a "blob") and subdivide it into even-size chunks, doling these out as needed. If the first blob gets full, we allocate additional blobs as necessary. A given pool can allocate blocks of only one size; if you need a different size, you should use a different pool.

Definition at line 280 of file GameMemory.h.

Constructor & Destructor Documentation

◆ MemoryPool()

MemoryPool::MemoryPool ( )

init to safe values.

Definition at line 1499 of file GameMemory.cpp.

◆ ~MemoryPool()

MemoryPool::~MemoryPool ( )

throw away the pool, and all blocks/blobs associated with it.

Definition at line 1542 of file GameMemory.cpp.

Member Function Documentation

◆ addToList()

void MemoryPool::addToList ( MemoryPool ** pHead)

add this pool to head of the linked list

add this pool to the factory's list-of-pools.

Definition at line 1816 of file GameMemory.cpp.

◆ allocateBlockDoNotZeroImplementation()

void * MemoryPool::allocateBlockDoNotZeroImplementation ( DECLARE_LITERALSTRING_ARG1 )

same as allocateBlockImplementation, but memory returned is not zeroed

allocate a block from this pool 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.

Definition at line 1630 of file GameMemory.cpp.

◆ allocateBlockImplementation()

void * MemoryPool::allocateBlockImplementation ( DECLARE_LITERALSTRING_ARG1 )

allocate a block from this pool. (don't call directly; use allocateBlock() macro)

allocate a block from this pool and return it, and zero out the contents of the block. if unable to allocate, throw ERROR_OUT_OF_MEMORY. this function will never return null.

Definition at line 1700 of file GameMemory.cpp.

◆ countBlobsInPool()

Int MemoryPool::countBlobsInPool ( )

Definition at line 1756 of file GameMemory.cpp.

◆ freeBlock()

void MemoryPool::freeBlock ( void * pBlockPtr)

free the block. it is OK to pass null.

free a block allocated by this pool. it's ok to pass null.

Definition at line 1711 of file GameMemory.cpp.

◆ getAllocationSize()

Int MemoryPool::getAllocationSize ( )
inline

return the block allocation size of this pool.

Definition at line 764 of file GameMemory.h.

◆ getFreeBlockCount()

Int MemoryPool::getFreeBlockCount ( )
inline

return the number of free (available) blocks in this pool.

Definition at line 765 of file GameMemory.h.

◆ getInitialBlockCount()

Int MemoryPool::getInitialBlockCount ( )
inline

return the initial allocation count for this pool

Definition at line 769 of file GameMemory.h.

◆ getNextPoolInList()

MemoryPool * MemoryPool::getNextPoolInList ( )
inline

return next pool in linked list

Definition at line 762 of file GameMemory.h.

◆ getOwningFactory()

MemoryPoolFactory * MemoryPool::getOwningFactory ( )
inline

return the factory that created (and thus owns) this pool.

Definition at line 761 of file GameMemory.h.

◆ getPeakBlockCount()

Int MemoryPool::getPeakBlockCount ( )
inline

return the high-water mark for getUsedBlockCount()

Definition at line 768 of file GameMemory.h.

◆ getPoolName()

const char * MemoryPool::getPoolName ( )
inline

return the name of this pool. the result is a literal string and must not be freed.

Definition at line 763 of file GameMemory.h.

◆ getTotalBlockCount()

Int MemoryPool::getTotalBlockCount ( )
inline

return the total number of blocks in this pool. [ == getFreeBlockCount() + getUsedBlockCount() ]

Definition at line 767 of file GameMemory.h.

◆ getUsedBlockCount()

Int MemoryPool::getUsedBlockCount ( )
inline

return the number of blocks in use in this pool.

Definition at line 766 of file GameMemory.h.

◆ init()

void MemoryPool::init ( MemoryPoolFactory * factory,
const char * poolName,
Int allocationSize,
Int initialAllocationCount,
Int overflowAllocationCount )

initialize the given memory pool.

initialize the memory pool with the given parameters. allocate the initial set of blocks.

Definition at line 1520 of file GameMemory.cpp.

◆ releaseEmpties()

Int MemoryPool::releaseEmpties ( )

if this pool has any empty blobs, return them to the system.

if the pool has any blobs that are completely unused, they are released back to the operating system. this will rarely, if ever, be called, but may be useful in odd situations.

Definition at line 1773 of file GameMemory.cpp.

◆ removeFromList()

void MemoryPool::removeFromList ( MemoryPool ** pHead)

remove this pool from the linked list

remove this pool from the factory's list-of-pools.

Definition at line 1826 of file GameMemory.cpp.

◆ reset()

void MemoryPool::reset ( )

destroy all blocks and blobs in this pool.

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

Definition at line 1794 of file GameMemory.cpp.


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