//MemoryPool.h //Lee Noll #ifndef __MEMORY_POOL_H #define __MEMORY_POOL_H #ifndef _WIN32 #include #endif //This must be the base class of all new'd objects class CMemoryPool { private: CMemoryPool *m_pParent; void * m_pFree; size_t m_nCount; static void * m_pTempThis; static CMemoryPool *m_pTempParent; static void * m_pTempFree; static size_t m_nTempCount; static CMemoryPool *MostRemovedAncestor(CMemoryPool *pParent); static void * Alloc(size_t stAllocateBlock, CMemoryPool *pParent); static size_t Align(size_t stAllocateBlock); protected: void * Alloc(size_t stAllocateBlock); void Free(void *pvMem) {} public: CMemoryPool(); virtual ~CMemoryPool(); //establish the Memory Pool for all subsequent allocations //these hide the global operator new void * operator new (size_t stAllocateBlock, size_t total); //allocate from the most removed ancestor's pool void * operator new (size_t stAllocateBlock, CMemoryPool *pParent); //doesn't do anything to reverse the second new, only the first one //this hides the global operator delete void operator delete (void *pvMem); void operator delete (void *pvMem, size_t total); void operator delete (void *pvMem, CMemoryPool *pParent); }; #endif