00001 #ifndef IG_HOOK_IG_HOOK_ALLOC_H 00002 # define IG_HOOK_IG_HOOK_ALLOC_H 00003 00004 //<<<<<< INCLUDES >>>>>> 00005 00006 # include <memory> 00007 # include <cstdlib> 00008 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) 00009 // https://gcc.gnu.org/onlinedocs/libstdc++/20_util/allocator.html 00010 # include <ext/pool_allocator.h> 00011 # endif 00012 00013 //<<<<<< PUBLIC DEFINES >>>>>> 00014 //<<<<<< PUBLIC CONSTANTS >>>>>> 00015 //<<<<<< PUBLIC TYPES >>>>>> 00016 //<<<<<< PUBLIC VARIABLES >>>>>> 00017 //<<<<<< PUBLIC FUNCTIONS >>>>>> 00018 //<<<<<< CLASS DECLARATIONS >>>>>> 00019 00020 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) 00021 template <class T> class IgHookAlloc : public __gnu_cxx::__pool_alloc<T> {}; 00022 # elif __GNUC__ == 3 && __GNUC_MINOR__ <= 2 00023 template <class T> 00024 class IgHookAlloc : public std::__allocator<T, std::__default_alloc_template<true,-789> > 00025 { 00026 }; 00027 # else 00028 template <class T> 00029 class IgHookAlloc : public std::allocator<T> 00030 { 00031 public: 00032 template <class O> struct rebind 00033 { 00034 typedef IgHookAlloc<O> other; 00035 }; 00036 00037 typedef typename std::allocator<T>::size_type size_type; 00038 typedef typename std::allocator<T>::pointer pointer; 00039 00040 IgHookAlloc (void) throw (); 00041 IgHookAlloc (const IgHookAlloc &x) throw (); 00042 template <class O> IgHookAlloc (const IgHookAlloc<O> &x) throw (); 00043 ~IgHookAlloc (void) throw (); 00044 00045 T *allocate (size_type n, const T *hint = 0); 00046 void deallocate (pointer p, size_type count); 00047 }; 00048 00049 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> 00050 //<<<<<< INLINE MEMBER FUNCTIONS >>>>>> 00051 00052 template <class T> 00053 inline 00054 IgHookAlloc<T>::IgHookAlloc (void) throw () 00055 {} 00056 00057 template <class T> 00058 inline 00059 IgHookAlloc<T>::IgHookAlloc (const IgHookAlloc &x) throw () 00060 : std::allocator<T> (x) 00061 {} 00062 00063 template <class T> 00064 template <class O> 00065 inline 00066 IgHookAlloc<T>::IgHookAlloc (const IgHookAlloc<O> &x) throw () 00067 : std::allocator<T> (x) 00068 {} 00069 00070 template <class T> 00071 inline 00072 IgHookAlloc<T>::~IgHookAlloc (void) throw () 00073 {} 00074 00075 template <class T> 00076 inline T * 00077 IgHookAlloc<T>::allocate (size_type n, const T * /* hint = 0 */) 00078 { return (T *) malloc (n * sizeof (T)); } 00079 00080 template <class T> 00081 inline void 00082 IgHookAlloc<T>::deallocate (pointer p, size_type /* n */) 00083 { free (p); } 00084 00085 # endif // __GNUC__ 00086 #endif // IG_HOOK_IG_HOOK_ALLOC_H