00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #ifndef __TBB_cache_aligned_allocator_H
00022 #define __TBB_cache_aligned_allocator_H
00023 
00024 #include <new>
00025 #include "tbb_stddef.h"
00026 
00027 namespace tbb {
00028 
00030 namespace internal {
00032 
00033     size_t __TBB_EXPORTED_FUNC NFS_GetLineSize();
00034 
00036 
00037     void* __TBB_EXPORTED_FUNC NFS_Allocate( size_t n_element, size_t element_size, void* hint );
00038 
00040 
00042     void __TBB_EXPORTED_FUNC NFS_Free( void* );
00043 }
00045 
00046 #if _MSC_VER && !defined(__INTEL_COMPILER)
00047     
00048     #pragma warning (push)
00049     #pragma warning (disable: 4100)
00050 #endif
00051 
00053 
00056 template<typename T>
00057 class cache_aligned_allocator {
00058 public:
00059     typedef typename internal::allocator_type<T>::value_type value_type;
00060     typedef value_type* pointer;
00061     typedef const value_type* const_pointer;
00062     typedef value_type& reference;
00063     typedef const value_type& const_reference;
00064     typedef size_t size_type;
00065     typedef ptrdiff_t difference_type;
00066     template<typename U> struct rebind {
00067         typedef cache_aligned_allocator<U> other;
00068     };
00069 
00070     cache_aligned_allocator() throw() {}
00071     cache_aligned_allocator( const cache_aligned_allocator& ) throw() {}
00072     template<typename U> cache_aligned_allocator(const cache_aligned_allocator<U>&) throw() {}
00073 
00074     pointer address(reference x) const {return &x;}
00075     const_pointer address(const_reference x) const {return &x;}
00076     
00078     pointer allocate( size_type n, const void* hint=0 ) {
00079         
00080         return pointer(internal::NFS_Allocate( n, sizeof(value_type), const_cast<void*>(hint) ));
00081     }
00082 
00084     void deallocate( pointer p, size_type ) {
00085         internal::NFS_Free(p);
00086     }
00087 
00089     size_type max_size() const throw() {
00090         return (~size_t(0)-internal::NFS_MaxLineSize)/sizeof(value_type);
00091     }
00092 
00094     void construct( pointer p, const value_type& value ) {new(static_cast<void*>(p)) value_type(value);}
00095 
00097     void destroy( pointer p ) {p->~value_type();}
00098 };
00099 
00100 #if _MSC_VER && !defined(__INTEL_COMPILER)
00101     #pragma warning (pop)
00102 #endif // warning 4100 is back
00103 
00105 
00106 template<> 
00107 class cache_aligned_allocator<void> {
00108 public:
00109     typedef void* pointer;
00110     typedef const void* const_pointer;
00111     typedef void value_type;
00112     template<typename U> struct rebind {
00113         typedef cache_aligned_allocator<U> other;
00114     };
00115 };
00116 
00117 template<typename T, typename U>
00118 inline bool operator==( const cache_aligned_allocator<T>&, const cache_aligned_allocator<U>& ) {return true;}
00119 
00120 template<typename T, typename U>
00121 inline bool operator!=( const cache_aligned_allocator<T>&, const cache_aligned_allocator<U>& ) {return false;}
00122 
00123 } 
00124 
00125 #endif