00001 #ifdef CH_LANG_CC 00002 /* 00003 * _______ __ 00004 * / ___/ / ___ __ _ / / ___ 00005 * / /__/ _ \/ _ \/ V \/ _ \/ _ \ 00006 * \___/_//_/\___/_/_/_/_.__/\___/ 00007 * Please refer to Copyright.txt, in Chombo's root directory. 00008 */ 00009 #endif 00010 00011 #ifndef _POOL_H_ 00012 #define _POOL_H_ 00013 00014 #include <cstdlib> 00015 #include <list> 00016 00017 #include "Vector.H" 00018 #include "BaseNamespaceHeader.H" 00019 00020 class Pool; 00021 typedef std::list<Pool*> PoolList; 00022 00024 00063 class Pool { 00064 public: 00066 00077 Pool(int a_ptrSize, 00078 const char* a_name = "unnamed", 00079 int a_poolSize = 100, 00080 int a_alignment = sizeof(int)); 00081 00083 ~Pool(); 00084 00086 void* getPtr(); 00087 00089 void returnPtr(void* a_ptr); 00090 00092 00098 long memUsage() const; 00099 00105 void clear(); 00106 00107 // not for public consumption. used in memory tracking code. 00108 static PoolList* m_poolList_; 00109 char m_name_[64]; 00110 00111 00112 protected: 00113 00114 00115 private: 00117 Vector<char*> m_pool_; 00118 00120 int m_ptrSize_; 00121 00123 int m_poolSize_; 00124 00126 int m_alignment_; 00127 00129 void* m_next_; 00130 00132 void* getMoreMemory(); 00133 00134 void* getMore(); 00135 00138 Pool(const Pool& a_rhs); 00139 00141 const Pool& operator = (const Pool& a_rhs); 00142 00143 static void clearAllPools(); 00144 00145 friend void dumpmemoryatexit(); 00146 }; 00147 00148 // Stroustrup (S. 11.5.1) says a declaration in the global scope is needed 00149 void dumpmemoryatexit(); 00150 00151 #include "BaseNamespaceFooter.H" 00152 #endif