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
00060 int __TBB_EXPORTED_FUNC scalable_posix_memalign (void** memptr, size_t alignment, size_t size);
00061
00064 void * __TBB_EXPORTED_FUNC scalable_aligned_malloc (size_t size, size_t alignment);
00065
00068 void * __TBB_EXPORTED_FUNC scalable_aligned_realloc (void* ptr, size_t size, size_t alignment);
00069
00072 void __TBB_EXPORTED_FUNC scalable_aligned_free (void* ptr);
00073
00074 #ifdef __cplusplus
00075 }
00076 #endif
00077
00078 #ifdef __cplusplus
00079
00080 #include <new>
00081
00082
00083 #ifndef __TBB_NO_IMPLICIT_LINKAGE
00084 #define __TBB_NO_IMPLICIT_LINKAGE 1
00085 #include "tbb_stddef.h"
00086 #undef __TBB_NO_IMPLICIT_LINKAGE
00087 #else
00088 #include "tbb_stddef.h"
00089 #endif
00090
00091
00092 namespace tbb {
00093
00094 #if _MSC_VER && !defined(__INTEL_COMPILER)
00095
00096 #pragma warning (push)
00097 #pragma warning (disable: 4100)
00098 #endif
00099
00101
00104 template<typename T>
00105 class scalable_allocator {
00106 public:
00107 typedef typename internal::allocator_type<T>::value_type value_type;
00108 typedef value_type* pointer;
00109 typedef const value_type* const_pointer;
00110 typedef value_type& reference;
00111 typedef const value_type& const_reference;
00112 typedef size_t size_type;
00113 typedef ptrdiff_t difference_type;
00114 template<class U> struct rebind {
00115 typedef scalable_allocator<U> other;
00116 };
00117
00118 scalable_allocator() throw() {}
00119 scalable_allocator( const scalable_allocator& ) throw() {}
00120 template<typename U> scalable_allocator(const scalable_allocator<U>&) throw() {}
00121
00122 pointer address(reference x) const {return &x;}
00123 const_pointer address(const_reference x) const {return &x;}
00124
00126 pointer allocate( size_type n, const void* =0 ) {
00127 return static_cast<pointer>( scalable_malloc( n * sizeof(value_type) ) );
00128 }
00129
00131 void deallocate( pointer p, size_type ) {
00132 scalable_free( p );
00133 }
00134
00136 size_type max_size() const throw() {
00137 size_type absolutemax = static_cast<size_type>(-1) / sizeof (value_type);
00138 return (absolutemax > 0 ? absolutemax : 1);
00139 }
00140 void construct( pointer p, const value_type& val ) { new(static_cast<void*>(p)) value_type(val); }
00141 void destroy( pointer p ) {p->~value_type();}
00142 };
00143
00144 #if _MSC_VER && !defined(__INTEL_COMPILER)
00145 #pragma warning (pop)
00146 #endif // warning 4100 is back
00147
00149
00150 template<>
00151 class scalable_allocator<void> {
00152 public:
00153 typedef void* pointer;
00154 typedef const void* const_pointer;
00155 typedef void value_type;
00156 template<class U> struct rebind {
00157 typedef scalable_allocator<U> other;
00158 };
00159 };
00160
00161 template<typename T, typename U>
00162 inline bool operator==( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return true;}
00163
00164 template<typename T, typename U>
00165 inline bool operator!=( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return false;}
00166
00167 }
00168
00169 #if _MSC_VER
00170 #if __TBB_BUILD && !defined(__TBBMALLOC_NO_IMPLICIT_LINKAGE)
00171 #define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1
00172 #endif
00173
00174 #if !__TBBMALLOC_NO_IMPLICIT_LINKAGE
00175 #ifdef _DEBUG
00176 #pragma comment(lib, "tbbmalloc_debug.lib")
00177 #else
00178 #pragma comment(lib, "tbbmalloc.lib")
00179 #endif
00180 #endif
00181 #endif
00182
00183 #endif
00184
00185 #if !defined(__cplusplus) && __ICC==1100
00186 #pragma warning (pop)
00187 #endif // ICC 11.0 warning 991 is back
00188
00189 #endif