#include <GameMemory.h>
Public Member Functions | |
| MemoryPool * | getNextPoolInList () |
| 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. | |
| MemoryPoolFactory * | getOwningFactory () |
| 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. | |
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.
| MemoryPool::MemoryPool | ( | ) |
init to safe values.
Definition at line 1499 of file GameMemory.cpp.
| MemoryPool::~MemoryPool | ( | ) |
throw away the pool, and all blocks/blobs associated with it.
Definition at line 1542 of file GameMemory.cpp.
| 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.
| 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.
| 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.
| Int MemoryPool::countBlobsInPool | ( | ) |
Definition at line 1756 of file GameMemory.cpp.
| 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.
|
inline |
return the block allocation size of this pool.
Definition at line 764 of file GameMemory.h.
|
inline |
return the number of free (available) blocks in this pool.
Definition at line 765 of file GameMemory.h.
|
inline |
return the initial allocation count for this pool
Definition at line 769 of file GameMemory.h.
|
inline |
return next pool in linked list
Definition at line 762 of file GameMemory.h.
|
inline |
return the factory that created (and thus owns) this pool.
Definition at line 761 of file GameMemory.h.
|
inline |
return the high-water mark for getUsedBlockCount()
Definition at line 768 of file GameMemory.h.
|
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.
|
inline |
return the total number of blocks in this pool. [ == getFreeBlockCount() + getUsedBlockCount() ]
Definition at line 767 of file GameMemory.h.
|
inline |
return the number of blocks in use in this pool.
Definition at line 766 of file GameMemory.h.
| 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.
| 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.
| 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.
| 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.