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 __TBB_EXPORTED_FUNC deallocate_via_handler_v3( void *p );
00035
00037
00038 void* __TBB_EXPORTED_FUNC allocate_via_handler_v3( size_t n );
00039
00041 bool __TBB_EXPORTED_FUNC is_malloc_used_v3();
00042 }
00044
00045 #if _MSC_VER && !defined(__INTEL_COMPILER)
00046
00047 #pragma warning (push)
00048 #pragma warning (disable: 4100)
00049 #endif
00050
00052
00057 template<typename T>
00058 class tbb_allocator {
00059 public:
00060 typedef typename internal::allocator_type<T>::value_type value_type;
00061 typedef value_type* pointer;
00062 typedef const value_type* const_pointer;
00063 typedef value_type& reference;
00064 typedef const value_type& const_reference;
00065 typedef size_t size_type;
00066 typedef ptrdiff_t difference_type;
00067 template<typename U> struct rebind {
00068 typedef tbb_allocator<U> other;
00069 };
00070
00072 enum malloc_type {
00073 scalable,
00074 standard
00075 };
00076
00077 tbb_allocator() throw() {}
00078 tbb_allocator( const tbb_allocator& ) throw() {}
00079 template<typename U> tbb_allocator(const tbb_allocator<U>&) throw() {}
00080
00081 pointer address(reference x) const {return &x;}
00082 const_pointer address(const_reference x) const {return &x;}
00083
00085 pointer allocate( size_type n, const void* = 0) {
00086 return pointer(internal::allocate_via_handler_v3( n * sizeof(value_type) ));
00087 }
00088
00090 void deallocate( pointer p, size_type ) {
00091 internal::deallocate_via_handler_v3(p);
00092 }
00093
00095 size_type max_size() const throw() {
00096 size_type max = static_cast<size_type>(-1) / sizeof (value_type);
00097 return (max > 0 ? max : 1);
00098 }
00099
00101 void construct( pointer p, const value_type& value ) {new(static_cast<void*>(p)) value_type(value);}
00102
00104 void destroy( pointer p ) {p->~value_type();}
00105
00107 static malloc_type allocator_type() {
00108 return internal::is_malloc_used_v3() ? standard : scalable;
00109 }
00110 };
00111
00112 #if _MSC_VER && !defined(__INTEL_COMPILER)
00113 #pragma warning (pop)
00114 #endif // warning 4100 is back
00115
00117
00118 template<>
00119 class tbb_allocator<void> {
00120 public:
00121 typedef void* pointer;
00122 typedef const void* const_pointer;
00123 typedef void value_type;
00124 template<typename U> struct rebind {
00125 typedef tbb_allocator<U> other;
00126 };
00127 };
00128
00129 template<typename T, typename U>
00130 inline bool operator==( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return true;}
00131
00132 template<typename T, typename U>
00133 inline bool operator!=( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return false;}
00134
00135 }
00136
00137 #endif