Game Development Reference
In-Depth Information
This is perfectly fine and has absolutely no effect on the performance of the system.
Now that you have an understanding of what a memory pool is, let
'
s take a look at
the implementation of the MemoryPool class:
class MemoryPool
{
unsigned char** m_ppRawMemoryArray; // an array of memory blocks, each
// split up into chunks
unsigned char* m_pHead; // the front of the memory chunk linked list
unsigned int m_chunkSize, m_numChunks; // the size of each chunk and
// number of chunks per array
unsigned int m_memArraySize; // the number elements in the memory array
bool m_toAllowResize; // true if we resize the memory pool when it fills
public:
// construction
MemoryPool(void);
˜
MemoryPool(void);
bool Init(unsigned int chunkSize, unsigned int numChunks);
void Destroy(void);
// allocation functions
void* Alloc(void);
void Free(void* pMem);
unsigned int GetChunkSize(void) const { return m_chunkSize; }
// settings
void SetAllowResize(bool toAllowResize)
{
m_toAllowResize = toAllowResize;
}
private:
// resets internal vars
void Reset(void);
// internal memory allocation helpers
bool GrowMemoryArray(void);
unsigned char* AllocateNewMemoryBlock(void);
// internal linked list management
unsigned char* GetNext(unsigned char* pBlock);
void SetNext(unsigned char* pBlockToChange, unsigned char* pNewNext);
// don
t allow copy constructor
MemoryPool(const MemoryPool& memPool) {}
'
};
Search WWH ::




Custom Search