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 #if !_MSC_VER
00027 #include <stdint.h>
00028 #endif
00029
00030 #if !defined(__cplusplus) && __ICC==1100
00031 #pragma warning (push)
00032 #pragma warning (disable: 991)
00033 #endif
00034
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038
00039 #if _MSC_VER >= 1400
00040 #define __TBB_EXPORTED_FUNC __cdecl
00041 #else
00042 #define __TBB_EXPORTED_FUNC
00043 #endif
00044
00047 void * __TBB_EXPORTED_FUNC scalable_malloc (size_t size);
00048
00051 void __TBB_EXPORTED_FUNC scalable_free (void* ptr);
00052
00055 void * __TBB_EXPORTED_FUNC scalable_realloc (void* ptr, size_t size);
00056
00059 void * __TBB_EXPORTED_FUNC scalable_calloc (size_t nobj, size_t size);
00060
00063 int __TBB_EXPORTED_FUNC scalable_posix_memalign (void** memptr, size_t alignment, size_t size);
00064
00067 void * __TBB_EXPORTED_FUNC scalable_aligned_malloc (size_t size, size_t alignment);
00068
00071 void * __TBB_EXPORTED_FUNC scalable_aligned_realloc (void* ptr, size_t size, size_t alignment);
00072
00075 void __TBB_EXPORTED_FUNC scalable_aligned_free (void* ptr);
00076
00081 size_t __TBB_EXPORTED_FUNC scalable_msize (void* ptr);
00082
00083 #ifdef __cplusplus
00084 }
00085 #endif
00086
00087 #ifdef __cplusplus
00088
00089 namespace rml {
00090 class MemoryPool;
00091
00092 #define MEM_POLICY_DEFINED 1
00093 typedef void *(*rawAllocType)(intptr_t pool_id, size_t &bytes);
00094 typedef int (*rawFreeType)(intptr_t pool_id, void* raw_ptr, size_t raw_bytes);
00095
00096 struct MemPoolPolicy {
00097 rawAllocType pAlloc;
00098 rawFreeType pFree;
00099 size_t granularity;
00100 void *pReserved;
00101 size_t szReserved;
00102 };
00103
00104 MemoryPool *pool_create(intptr_t pool_id, const MemPoolPolicy* memPoolPolicy);
00105 bool pool_destroy(MemoryPool* memPool);
00106 void *pool_malloc(MemoryPool* memPool, size_t size);
00107 void *pool_realloc(MemoryPool* memPool, void *object, size_t size);
00108 bool pool_reset(MemoryPool* memPool);
00109 bool pool_free(MemoryPool *memPool, void *object);
00110 }
00111
00112 #include <new>
00113
00114
00115 #ifndef __TBB_NO_IMPLICIT_LINKAGE
00116 #define __TBB_NO_IMPLICIT_LINKAGE 1
00117 #include "tbb_stddef.h"
00118 #undef __TBB_NO_IMPLICIT_LINKAGE
00119 #else
00120 #include "tbb_stddef.h"
00121 #endif
00122
00123
00124 namespace tbb {
00125
00126 #if _MSC_VER && !defined(__INTEL_COMPILER)
00127
00128 #pragma warning (push)
00129 #pragma warning (disable: 4100)
00130 #endif
00131
00133
00136 template<typename T>
00137 class scalable_allocator {
00138 public:
00139 typedef typename internal::allocator_type<T>::value_type value_type;
00140 typedef value_type* pointer;
00141 typedef const value_type* const_pointer;
00142 typedef value_type& reference;
00143 typedef const value_type& const_reference;
00144 typedef size_t size_type;
00145 typedef ptrdiff_t difference_type;
00146 template<class U> struct rebind {
00147 typedef scalable_allocator<U> other;
00148 };
00149
00150 scalable_allocator() throw() {}
00151 scalable_allocator( const scalable_allocator& ) throw() {}
00152 template<typename U> scalable_allocator(const scalable_allocator<U>&) throw() {}
00153
00154 pointer address(reference x) const {return &x;}
00155 const_pointer address(const_reference x) const {return &x;}
00156
00158 pointer allocate( size_type n, const void* =0 ) {
00159 return static_cast<pointer>( scalable_malloc( n * sizeof(value_type) ) );
00160 }
00161
00163 void deallocate( pointer p, size_type ) {
00164 scalable_free( p );
00165 }
00166
00168 size_type max_size() const throw() {
00169 size_type absolutemax = static_cast<size_type>(-1) / sizeof (value_type);
00170 return (absolutemax > 0 ? absolutemax : 1);
00171 }
00172 void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);}
00173 void destroy( pointer p ) {p->~value_type();}
00174 };
00175
00176 #if _MSC_VER && !defined(__INTEL_COMPILER)
00177 #pragma warning (pop)
00178 #endif // warning 4100 is back
00179
00181
00182 template<>
00183 class scalable_allocator<void> {
00184 public:
00185 typedef void* pointer;
00186 typedef const void* const_pointer;
00187 typedef void value_type;
00188 template<class U> struct rebind {
00189 typedef scalable_allocator<U> other;
00190 };
00191 };
00192
00193 template<typename T, typename U>
00194 inline bool operator==( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return true;}
00195
00196 template<typename T, typename U>
00197 inline bool operator!=( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return false;}
00198
00199 }
00200
00201 #if _MSC_VER
00202 #if __TBB_BUILD && !defined(__TBBMALLOC_NO_IMPLICIT_LINKAGE)
00203 #define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1
00204 #endif
00205
00206 #if !__TBBMALLOC_NO_IMPLICIT_LINKAGE
00207 #ifdef _DEBUG
00208 #pragma comment(lib, "tbbmalloc_debug.lib")
00209 #else
00210 #pragma comment(lib, "tbbmalloc.lib")
00211 #endif
00212 #endif
00213
00214
00215 #endif
00216
00217 #endif
00218
00219 #if !defined(__cplusplus) && __ICC==1100
00220 #pragma warning (pop)
00221 #endif // ICC 11.0 warning 991 is back
00222
00223 #endif