00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __TBB_scalable_allocator_H
00022 #define __TBB_scalable_allocator_H
00023
00024 #include <stddef.h>
00025
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029
00031
00032 void * scalable_malloc (size_t size);
00033
00035
00036 void scalable_free (void* ptr);
00037
00039
00040 void * scalable_realloc (void* ptr, size_t size);
00041
00043
00044 void * scalable_calloc (size_t nobj, size_t size);
00045
00046 #ifdef __cplusplus
00047 }
00048 #endif
00049
00050 #ifdef __cplusplus
00051
00052 #include <new>
00053
00054 namespace tbb {
00055
00057
00060 template<typename T>
00061 class scalable_allocator {
00062 public:
00063 typedef T* pointer;
00064 typedef const T* const_pointer;
00065 typedef T& reference;
00066 typedef const T& const_reference;
00067 typedef T value_type;
00068 typedef size_t size_type;
00069 typedef ptrdiff_t difference_type;
00070 template<class U> struct rebind {
00071 typedef scalable_allocator<U> other;
00072 };
00073
00074 scalable_allocator() throw() {}
00075 scalable_allocator( const scalable_allocator& ) throw() {}
00076 template<typename U> scalable_allocator(const scalable_allocator<U>&) throw() {}
00077
00078 pointer address(reference x) const {return &x;}
00079 const_pointer address(const_reference x) const {return &x;}
00080
00082 pointer allocate( size_type n, const void* =0 ) {
00083 return static_cast<pointer>( scalable_malloc( n * sizeof(value_type) ) );
00084 }
00085
00087 void deallocate( pointer p, size_type ) {
00088 scalable_free( p );
00089 }
00090
00092 size_type max_size() const throw() {
00093 size_type absolutemax = static_cast<size_type>(-1) / sizeof (T);
00094 return (absolutemax > 0 ? absolutemax : 1);
00095 }
00096 void construct( pointer p, const T& val ) { new(static_cast<void*>(p)) T(val); }
00097 void destroy( pointer p ) {(static_cast<T*>(p))->~T();}
00098 };
00099
00101
00102 template<>
00103 class scalable_allocator<void> {
00104 public:
00105 typedef void* pointer;
00106 typedef const void* const_pointer;
00107 typedef void value_type;
00108 template<class U> struct rebind {
00109 typedef scalable_allocator<U> other;
00110 };
00111 };
00112
00113 template<typename T, typename U>
00114 inline bool operator==( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return true;}
00115
00116 template<typename T, typename U>
00117 inline bool operator!=( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return false;}
00118
00119 }
00120
00121 #if _MSC_VER
00122 #if __TBB_BUILD && !defined(__TBBMALLOC_NO_IMPLICIT_LINKAGE)
00123 #define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1
00124 #endif
00125
00126 #if !__TBBMALLOC_NO_IMPLICIT_LINKAGE
00127 #ifdef _DEBUG
00128 #pragma comment(lib, "tbbmalloc_debug.lib")
00129 #else
00130 #pragma comment(lib, "tbbmalloc.lib")
00131 #endif
00132 #endif
00133 #endif
00134
00135 #endif
00136
00137 #endif