// File name: Mempool.h // Author: moonwell // msn: Archonzhao@hotmail.com// Put #include "mempool.h" Before #include , "INITIALIZECRITICTIONANDSPINCOUNT function will appear" not defined "error #ifndef _MEM_POOL_H # define _MEM_POOL_H # define _WIN32_WINNT 0x0403 // For InitializeCriticalSectionAndSpinCount # ifdef _DEBUG # define _DEBUG_POOL # endif # include #include #include #ifdef _DEBUG_POOL # include
// Take the last object m_free_node.pop_back (); # ifdef _debug_pool m_map.ed (ptmp); # Endif} else {ptmp = new memory; // Create an additional object m_new_node.push_back (ptmp); // Add to additional list} LeaveCriticalSection (& m_sec); return ptmp;} template void memPool :: free (memtype * obj) {EnterCriticalSection (& m_sec); m_free_node.push_back (obj); # ifdef _DEBUG_POOL // obj has been Released? _Asserte (m_map.find (obj) == m_map.end ()); m_map [obj] = Obj; #ndif leavecriticalsection (& m_sec);} # Endif increases multiple free () detection on the original basis The function, which will cause an assertion to the same object twice.