00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __TBB_tbb_allocator_H
00022 #define __TBB_tbb_allocator_H
00023
00024 #include <new>
00025 #include "tbb_stddef.h"
00026
00027 namespace tbb {
00028
00030 namespace internal {
00031
00033
00034 void deallocate_via_handler_v3( void *p );
00035
00037
00038 void* allocate_via_handler_v3( size_t n );
00039
00041 bool is_malloc_used_v3();
00042 }
00044
00046
00051 template<typename T>
00052 class tbb_allocator {
00053 public:
00054 typedef T* pointer;
00055 typedef const T* const_pointer;
00056 typedef T& reference;
00057 typedef const T& const_reference;
00058 typedef T value_type;
00059 typedef size_t size_type;
00060 typedef ptrdiff_t difference_type;
00061 template<typename U> struct rebind {
00062 typedef tbb_allocator<U> other;
00063 };
00064
00066 enum malloc_type {
00067 scalable,
00068 standard
00069 };
00070
00071 #if _WIN64
00072
00073
00075 char* _Charalloc( size_type size ) {
00076 return (char*)(internal::allocate_via_handler_v3( size * sizeof(T)));
00077 }
00078 #endif
00079
00080 tbb_allocator() throw() {}
00081 tbb_allocator( const tbb_allocator& ) throw() {}
00082 template<typename U> tbb_allocator(const tbb_allocator<U>&) throw() {}
00083
00084 pointer address(reference x) const {return &x;}
00085 const_pointer address(const_reference x) const {return &x;}
00086
00088 pointer allocate( size_type n, const void* = 0) {
00089 return pointer(internal::allocate_via_handler_v3( n * sizeof(T) ));
00090 }
00091
00093 void deallocate( pointer p, size_type ) {
00094 internal::deallocate_via_handler_v3(p);
00095 }
00096
00098 size_type max_size() const throw() {
00099 size_type max = static_cast<size_type>(-1) / sizeof (T);
00100 return (max > 0 ? max : 1);
00101 }
00102
00104 void construct( pointer p, const T& value ) {new(static_cast<void*>(p)) T(value);}
00105
00107 void destroy( pointer p ) {p->~T();}
00108
00110 static malloc_type allocator_type() {
00111 return internal::is_malloc_used_v3() ? standard : scalable;
00112 }
00113 };
00114
00116
00117 template<>
00118 class tbb_allocator<void> {
00119 public:
00120 typedef void* pointer;
00121 typedef const void* const_pointer;
00122 typedef void value_type;
00123 template<typename U> struct rebind {
00124 typedef tbb_allocator<U> other;
00125 };
00126 };
00127
00128 template<typename T, typename U>
00129 inline bool operator==( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return true;}
00130
00131 template<typename T, typename U>
00132 inline bool operator!=( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return false;}
00133
00134 }
00135
00136 #endif