00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * 00004 * The IPPL Framework 00005 * 00006 * 00007 * Visit http://people.web.psi.ch/adelmann/ for more details 00008 * 00009 ***************************************************************************/ 00010 00011 #ifndef POOLED_H 00012 #define POOLED_H 00013 00014 // include files 00015 #include "Utility/Pool.h" 00016 00018 00019 template <class T> 00020 class Pooled 00021 { 00022 #ifndef IPPL_DONT_POOL 00023 public: 00024 00025 // Here is the reason for the class: 00026 // Defining new and delete for the classes that inherit from it. 00027 00028 // Get some memory from the pool. 00029 inline void* operator new(size_t) { return MyPool.alloc(); } 00030 00031 // Move a piece of memory back to the pool. 00032 inline void operator delete(void *p, size_t) { if (p) MyPool.free(p); } 00033 00034 private: 00035 00036 static Pool MyPool; // Storage for objects of type T 00037 #endif 00038 }; 00039 00041 00042 #include "Utility/Pooled.cpp" 00043 00044 #endif // POOLED_H 00045 00046 /*************************************************************************** 00047 * $RCSfile: Pooled.h,v $ $Author: adelmann $ 00048 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $ 00049 * IPPL_VERSION_ID: $Id: Pooled.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 00050 ***************************************************************************/