1 /*************************************************************************** 2 * * 3 * This program is free software; you can redistribute it and/or modify * 4 * it under the terms of the GNU General Public License as published by * 5 * the Free Software Foundation; either version 3 of the License, or * 6 * (at your option) any later version. * 7 * * 8 ***************************************************************************/ 9 10 #pragma once 11 12 #include <boost/pool/pool_alloc.hpp> 13 #include <assert.h> 14 15 template <class T> 16 class PoolItem{ 17 public: PoolItem()18 PoolItem(){ 19 } 20 ~PoolItem()21 virtual ~PoolItem(){ 22 } 23 new(size_t s)24 static void* operator new(size_t s) { 25 assert(sizeof(T) == s); 26 27 return reinterpret_cast<void*>(pool.allocate()); 28 } 29 new(size_t,void * m)30 static void* operator new(size_t, void* m) { 31 return m; 32 } 33 delete(void *,void *)34 static void operator delete(void*, void*) { } 35 delete(void * m,size_t s)36 static void operator delete(void* m, size_t s) { 37 assert(sizeof(T) == s); 38 39 pool.deallocate(reinterpret_cast<T*>(m)); 40 } 41 42 private: 43 static boost::fast_pool_allocator<T> pool; 44 }; 45 46 template <class T> 47 boost::fast_pool_allocator<T> PoolItem<T>::pool = boost::fast_pool_allocator<T>(); 48