pool_allocator.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 #ifndef LIBMESH_POOL_ALLOCATOR_H 00019 #define LIBMESH_POOL_ALLOCATOR_H 00020 00021 #include "libmesh/libmesh_config.h" 00022 00023 #ifdef LIBMESH_HAVE_BOOST 00024 # include <boost/pool/pool.hpp> 00025 # include <boost/pool/object_pool.hpp> 00026 # include <boost/pool/pool_alloc.hpp> 00027 #endif 00028 00029 #include <memory> // std::allocator 00030 00031 namespace libMesh 00032 { 00033 // If Boost is enabled, wrappers to use their allocators. 00034 #ifdef LIBMESH_HAVE_BOOST 00035 00043 template <typename T> 00044 class PoolAllocator : public boost::pool_allocator<T> 00045 { 00046 public: 00047 00051 template<typename U> 00052 struct rebind { 00053 typedef PoolAllocator<U> other; 00054 }; 00055 00056 00057 PoolAllocator() : 00058 boost::pool_allocator<T>() 00059 {} 00060 00061 explicit PoolAllocator(const PoolAllocator &o) : 00062 boost::pool_allocator<T>(o) 00063 {} 00064 00069 static bool release_memory () 00070 { 00071 return boost::singleton_pool<boost::pool_allocator_tag, sizeof(T)>::release_memory(); 00072 } 00073 00078 static bool purge_memory () 00079 { 00080 return boost::singleton_pool<boost::pool_allocator_tag, sizeof(T)>::purge_memory(); 00081 } 00082 }; 00083 00084 00085 00093 template <typename T> 00094 class FastPoolAllocator : public boost::fast_pool_allocator<T> 00095 { 00096 public: 00097 00101 template<typename U> 00102 struct rebind { 00103 typedef FastPoolAllocator<U> other; 00104 }; 00105 00106 00107 FastPoolAllocator() : 00108 boost::fast_pool_allocator<T>() 00109 {} 00110 00111 explicit FastPoolAllocator(const FastPoolAllocator &o) : 00112 boost::fast_pool_allocator<T>(o) 00113 {} 00114 00115 00120 static bool release_memory () 00121 { 00122 return boost::singleton_pool<boost::fast_pool_allocator_tag, sizeof(T)>::release_memory(); 00123 } 00124 00129 static bool purge_memory () 00130 { 00131 return boost::singleton_pool<boost::fast_pool_allocator_tag, sizeof(T)>::purge_memory(); 00132 } 00133 }; 00134 00135 // Otherwise fall back to std::allocator<>. 00136 #else 00137 00142 template <typename T> 00143 class PoolAllocator : public std::allocator<T> 00144 { 00145 public: 00146 00150 template<typename U> 00151 struct rebind { 00152 typedef PoolAllocator<U> other; 00153 }; 00154 00155 PoolAllocator() : 00156 std::allocator<T>() 00157 {} 00158 00159 explicit PoolAllocator(const PoolAllocator &o) : 00160 std::allocator<T>(o) 00161 {} 00162 00167 static bool release_memory () { /* no-op for std::allocator<> - already freed. */ return false; } 00168 00173 static bool purge_memory () { /* no-op for std::allocator<> - already freed. */ return false; } 00174 }; 00175 00176 00177 00182 template <typename T> 00183 class FastPoolAllocator : public std::allocator<T> 00184 { 00185 public: 00186 00190 template<typename U> 00191 struct rebind { 00192 typedef FastPoolAllocator<U> other; 00193 }; 00194 00195 FastPoolAllocator() : 00196 std::allocator<T>() 00197 {} 00198 00199 explicit FastPoolAllocator(const FastPoolAllocator &o) : 00200 std::allocator<T>(o) 00201 {} 00202 00207 static bool release_memory () { /* no-op for std::allocator<> - already freed. */ return false; } 00208 00213 static bool purge_memory () { /* no-op for std::allocator<> - already freed. */ return false; } 00214 }; 00215 00216 #endif 00217 00218 } // end namespace libMesh 00219 00220 00221 #endif // LIBMESH_POOL_ALLOCATOR_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:48 UTC
Hosted By: