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 typedef void *(*rawAllocType)(intptr_t pool_id, size_t &bytes);
00093 typedef int (*rawFreeType)(intptr_t pool_id, void* raw_ptr, size_t raw_bytes);
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 struct MemPoolPolicy {
00106 enum {
00107 VERSION = 1
00108 };
00109
00110 rawAllocType pAlloc;
00111 rawFreeType pFree;
00112
00113 size_t granularity;
00114 int version;
00115
00116
00117 unsigned fixedPool : 1,
00118
00119 keepAllMemory : 1,
00120 reserved : 30;
00121
00122 MemPoolPolicy(rawAllocType pAlloc_, rawFreeType pFree_,
00123 size_t granularity_ = 0, bool fixedPool_ = false,
00124 bool keepAllMemory_ = false) :
00125 pAlloc(pAlloc_), pFree(pFree_), granularity(granularity_), version(VERSION),
00126 fixedPool(fixedPool_), keepAllMemory(keepAllMemory_),
00127 reserved(0) {}
00128 };
00129
00130 enum MemPoolError {
00131 POOL_OK,
00132 INVALID_POLICY,
00133 UNSUPPORTED_POLICY,
00134 NO_MEMORY
00135 };
00136
00137 MemPoolError pool_create_v1(intptr_t pool_id, const MemPoolPolicy *policy,
00138 rml::MemoryPool **pool);
00139
00140 bool pool_destroy(MemoryPool* memPool);
00141 void *pool_malloc(MemoryPool* memPool, size_t size);
00142 void *pool_realloc(MemoryPool* memPool, void *object, size_t size);
00143 void *pool_aligned_malloc(MemoryPool* mPool, size_t size, size_t alignment);
00144 void *pool_aligned_realloc(MemoryPool* mPool, void *ptr, size_t size, size_t alignment);
00145 bool pool_reset(MemoryPool* memPool);
00146 bool pool_free(MemoryPool *memPool, void *object);
00147 }
00148
00149 #include <new>
00150
00151
00152 #ifndef __TBB_NO_IMPLICIT_LINKAGE
00153 #define __TBB_NO_IMPLICIT_LINKAGE 1
00154 #include "tbb_stddef.h"
00155 #undef __TBB_NO_IMPLICIT_LINKAGE
00156 #else
00157 #include "tbb_stddef.h"
00158 #endif
00159
00160
00161 namespace tbb {
00162
00163 #if _MSC_VER && !defined(__INTEL_COMPILER)
00164
00165 #pragma warning (push)
00166 #pragma warning (disable: 4100)
00167 #endif
00168
00170
00173 template<typename T>
00174 class scalable_allocator {
00175 public:
00176 typedef typename internal::allocator_type<T>::value_type value_type;
00177 typedef value_type* pointer;
00178 typedef const value_type* const_pointer;
00179 typedef value_type& reference;
00180 typedef const value_type& const_reference;
00181 typedef size_t size_type;
00182 typedef ptrdiff_t difference_type;
00183 template<class U> struct rebind {
00184 typedef scalable_allocator<U> other;
00185 };
00186
00187 scalable_allocator() throw() {}
00188 scalable_allocator( const scalable_allocator& ) throw() {}
00189 template<typename U> scalable_allocator(const scalable_allocator<U>&) throw() {}
00190
00191 pointer address(reference x) const {return &x;}
00192 const_pointer address(const_reference x) const {return &x;}
00193
00195 pointer allocate( size_type n, const void* =0 ) {
00196 return static_cast<pointer>( scalable_malloc( n * sizeof(value_type) ) );
00197 }
00198
00200 void deallocate( pointer p, size_type ) {
00201 scalable_free( p );
00202 }
00203
00205 size_type max_size() const throw() {
00206 size_type absolutemax = static_cast<size_type>(-1) / sizeof (value_type);
00207 return (absolutemax > 0 ? absolutemax : 1);
00208 }
00209 void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);}
00210 void destroy( pointer p ) {p->~value_type();}
00211 };
00212
00213 #if _MSC_VER && !defined(__INTEL_COMPILER)
00214 #pragma warning (pop)
00215 #endif // warning 4100 is back
00216
00218
00219 template<>
00220 class scalable_allocator<void> {
00221 public:
00222 typedef void* pointer;
00223 typedef const void* const_pointer;
00224 typedef void value_type;
00225 template<class U> struct rebind {
00226 typedef scalable_allocator<U> other;
00227 };
00228 };
00229
00230 template<typename T, typename U>
00231 inline bool operator==( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return true;}
00232
00233 template<typename T, typename U>
00234 inline bool operator!=( const scalable_allocator<T>&, const scalable_allocator<U>& ) {return false;}
00235
00236 }
00237
00238 #if _MSC_VER
00239 #if __TBB_BUILD && !defined(__TBBMALLOC_NO_IMPLICIT_LINKAGE)
00240 #define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1
00241 #endif
00242
00243 #if !__TBBMALLOC_NO_IMPLICIT_LINKAGE
00244 #ifdef _DEBUG
00245 #pragma comment(lib, "tbbmalloc_debug.lib")
00246 #else
00247 #pragma comment(lib, "tbbmalloc.lib")
00248 #endif
00249 #endif
00250
00251
00252 #endif
00253
00254 #endif
00255
00256 #if !defined(__cplusplus) && __ICC==1100
00257 #pragma warning (pop)
00258 #endif // ICC 11.0 warning 991 is back
00259
00260 #endif