00001
00002
00003 #ifndef POOL_ALLOCATOR_H
00004 #define POOL_ALLOCATOR_H
00005
00006 #ifdef USE_TBB_SCALABLE_ALLOCATOR
00007 # include <tbb/scalable_allocator.h>
00008 #endif
00009 #ifdef USE_GPL_POOL_ALLOCATOR
00010
00011 # include "osl/stl/gnu_pool_alloc.h"
00012 #else
00013 # include <memory>
00014 #endif
00015
00016 namespace osl
00017 {
00029 namespace stl
00030 {
00031 extern const int gpl_pool_allocator_used;
00032 struct ConsistencyCheck
00033 {
00034 ConsistencyCheck(int);
00035 };
00036 #ifdef USE_TBB_SCALABLE_ALLOCATOR
00037 static ConsistencyCheck consistency_check(-1);
00038 template <class T>
00039 struct pool_allocator : tbb::scalable_allocator<T>
00040 {
00041 pool_allocator() {}
00042 template <class T2>
00043 pool_allocator(const tbb::scalable_allocator<T2>&) {}
00044 };
00045 #else
00046 #ifndef USE_GPL_POOL_ALLOCATOR
00047 static ConsistencyCheck consistency_check(0);
00048 template <class T>
00049 struct pool_allocator : std::allocator<T>
00050 {
00051 pool_allocator() {}
00052 template <class T2>
00053 pool_allocator(const std::allocator<T2>&) {}
00054 };
00055 #else
00056 static ConsistencyCheck consistency_check(1);
00057 # if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)
00058 template <class T>
00059 struct pool_allocator : __gnu_cxx::__pool_alloc<T>
00060 {
00061 pool_allocator() {}
00062 template <class T2>
00063 pool_allocator(const __gnu_cxx::__pool_alloc<T2>&) {}
00064 };
00065 # else
00066 template <class T, bool STL_MT=true>
00067 struct pool_allocator
00068 {
00069 typedef typename ::osl::__gnu_cxx::__pool_alloc<STL_MT,0> allocator_t;
00070 public:
00071 typedef T* pointer;
00072 typedef const T* const_pointer;
00073 typedef T& reference;
00074 typedef const T& const_reference;
00075 typedef size_t size_type;
00076 typedef size_t difference_type;
00077
00078 pool_allocator() {}
00079 template <class T2>
00080 pool_allocator(const pool_allocator<T2>&) {}
00081
00082 static T* allocate(size_t n)
00083 {
00084 T* ret = 0;
00085 if (n)
00086 ret = static_cast<T*>(allocator_t::allocate(n * sizeof(T)));
00087 return ret;
00088 }
00089
00090 static T* allocate()
00091 {
00092 return static_cast<T*>(allocator_t::allocate(sizeof(T)));
00093 }
00094
00095 static void deallocate(T* p, size_t n)
00096 {
00097 if (n)
00098 allocator_t::deallocate(p, n * sizeof(T));
00099 }
00100 static void deallocate(T* p) { allocator_t::deallocate(p, sizeof(T)); }
00101
00102 template<typename T2>
00103 struct rebind { typedef pool_allocator<T2> other; };
00104 };
00105 template <class T>
00106 inline bool
00107 operator==(const pool_allocator<T>&,const pool_allocator<T>&){
00108 return true;
00109 }
00110 # endif
00111 #endif
00112 #endif
00113 }
00114 }
00115
00116 #endif
00117
00118
00119
00120