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
00025 #include <stddef.h>
00026
00027 #if !defined(__cplusplus) && __ICC==1100
00028 #pragma warning (push)
00029 #pragma warning (disable: 991)
00030 #endif
00031
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035
00036 #if _MSC_VER >= 1400
00037 #define __TBB_EXPORTED_FUNC __cdecl
00038 #else
00039 #define __TBB_EXPORTED_FUNC
00040 #endif
00041
00044 void * __TBB_EXPORTED_FUNC scalable_malloc (size_t size);
00045
00048 void __TBB_EXPORTED_FUNC scalable_free (void* ptr);
00049
00052 void * __TBB_EXPORTED_FUNC scalable_realloc (void* ptr, size_t size);
00053
00056 void * __TBB_EXPORTED_FUNC scalable_calloc (size_t nobj, size_t size);
00057
00058 #ifdef __cplusplus
00059 }
00060 #endif
00061
00062 #ifdef __cplusplus
00063
00064 #include <new>
00065
00066 namespace tbb {
00067
00068 #if _MSC_VER && !defined(__INTEL_COMPILER)
00069
00070 #pragma warning (push)
00071 #pragma warning (disable: 4100)
00072 #endif
00073
00075
00078 template<typename T>
00079 class scalable_allocator {
00080 public:
00081 typedef T* pointer;
00082 typedef const T* const_pointer;
00083 typedef T& reference;
00084 typedef const T& const_reference;
00085 typedef T value_type;
00086 typedef size_t size_type;
00087 typedef ptrdiff_t difference_type;
00088 template<class U> struct rebind {
00089 typedef scalable_allocator<U> other;
00090 };
00091
00092 scalable_allocator() throw() {}
00093 scalable_allocator( const scalable_allocator& ) throw() {}
00094 template<typename U> scalable_allocator(const scalable_allocator<U>&) throw() {}
00095
00096 pointer address(reference x) const {return &x;}
00097 const_pointer address(const_reference x) const {return &x;}
00098
00100 pointer allocate( size_type n, const void* =0 ) {
00101 return static_cast<pointer>( scalable_malloc( n * sizeof(value_type) ) );
00102 }
00103
00105 void deallocate( pointer p, size_type ) {
00106 scalable_free( p );
00107 }
00108
00110 size_type max_size() const throw() {
00111 size_type absolutemax = static_cast<size_type>(-1) / sizeof (T);
00112 return (absolutemax > 0 ? absolutemax : 1);
00113 }
00114 void construct( pointer p, const T& val ) { new(static_cast<void*>(p)) T(val); }
00115 void destroy( pointer p ) {p->~T();}
00116 };
00117
00118 #if _MSC_VER && !defined(__INTEL_COMPILER)
00119 #pragma warning (pop)
00120 #endif // warning 4100 is back
00121
00123
00124 template<>
00125 class scalable_allocator<void> {
00126 public:
00127 typedef void* pointer;
00128 typedef const void* const_pointer;
00129 typedef void value_type;
00130 template<class U> struct rebind {
00131 typedef scalable_allocator<U> other;
00132 };
00133 };
00134
00135 template<typename T, typename U>
00136 inline bool operator==( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return true;}
00137
00138 template<typename T, typename U>
00139 inline bool operator!=( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return false;}
00140
00141 }
00142
00143 #if _MSC_VER
00144 #if __TBB_BUILD && !defined(__TBBMALLOC_NO_IMPLICIT_LINKAGE)
00145 #define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1
00146 #endif
00147
00148 #if !__TBBMALLOC_NO_IMPLICIT_LINKAGE
00149 #ifdef _DEBUG
00150 #pragma comment(lib, "tbbmalloc_debug.lib")
00151 #else
00152 #pragma comment(lib, "tbbmalloc.lib")
00153 #endif
00154 #endif
00155 #endif
00156
00157 #endif
00158
00159 #if !defined(__cplusplus) && __ICC==1100
00160 #pragma warning (pop)
00161 #endif // ICC 11.0 warning 991 is back
00162
00163 #endif