Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
cache_aligned_allocator.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2018 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16 
17 
18 
19 */
20 
21 #ifndef __TBB_cache_aligned_allocator_H
22 #define __TBB_cache_aligned_allocator_H
23 
24 #include <new>
25 #include "tbb_stddef.h"
26 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
27  #include <utility> // std::forward
28 #endif
29 
30 namespace tbb {
31 
33 namespace internal {
35 
37 
39 
40  void* __TBB_EXPORTED_FUNC NFS_Allocate( size_t n_element, size_t element_size, void* hint );
41 
43 
45  void __TBB_EXPORTED_FUNC NFS_Free( void* );
46 }
48 
49 #if _MSC_VER && !defined(__INTEL_COMPILER)
50  // Workaround for erroneous "unreferenced parameter" warning in method destroy.
51  #pragma warning (push)
52  #pragma warning (disable: 4100)
53 #endif
54 
56 
59 template<typename T>
61 public:
63  typedef value_type* pointer;
64  typedef const value_type* const_pointer;
66  typedef const value_type& const_reference;
67  typedef size_t size_type;
68  typedef ptrdiff_t difference_type;
69  template<typename U> struct rebind {
71  };
72 
75  template<typename U> cache_aligned_allocator(const cache_aligned_allocator<U>&) throw() {}
76 
77  pointer address(reference x) const {return &x;}
78  const_pointer address(const_reference x) const {return &x;}
79 
81  pointer allocate( size_type n, const void* hint=0 ) {
82  // The "hint" argument is always ignored in NFS_Allocate thus const_cast shouldn't hurt
83  return pointer(internal::NFS_Allocate( n, sizeof(value_type), const_cast<void*>(hint) ));
84  }
85 
89  }
90 
92  size_type max_size() const throw() {
93  return (~size_t(0)-internal::NFS_MaxLineSize)/sizeof(value_type);
94  }
95 
97 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
98  template<typename U, typename... Args>
99  void construct(U *p, Args&&... args)
100  { ::new((void *)p) U(std::forward<Args>(args)...); }
101 #else // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
102 #if __TBB_CPP11_RVALUE_REF_PRESENT
103  void construct( pointer p, value_type&& value ) {::new((void*)(p)) value_type(std::move(value));}
104 #endif
105  void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);}
106 #endif // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
107 
109  void destroy( pointer p ) {p->~value_type();}
110 };
111 
112 #if _MSC_VER && !defined(__INTEL_COMPILER)
113  #pragma warning (pop)
114 #endif // warning 4100 is back
115 
117 
118 template<>
120 public:
121  typedef void* pointer;
122  typedef const void* const_pointer;
123  typedef void value_type;
124  template<typename U> struct rebind {
126  };
127 };
128 
129 template<typename T, typename U>
130 inline bool operator==( const cache_aligned_allocator<T>&, const cache_aligned_allocator<U>& ) {return true;}
131 
132 template<typename T, typename U>
133 inline bool operator!=( const cache_aligned_allocator<T>&, const cache_aligned_allocator<U>& ) {return false;}
134 
135 } // namespace tbb
136 
137 #endif /* __TBB_cache_aligned_allocator_H */
size_type max_size() const
Largest value for which method allocate might succeed.
const_pointer address(const_reference x) const
#define __TBB_EXPORTED_FUNC
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
Definition: tbb_stddef.h:220
bool operator==(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
pointer address(reference x) const
void deallocate(pointer p, size_type)
Free block of memory that starts on a cache line.
void const char const char int ITT_FORMAT __itt_group_sync p
internal::allocator_type< T >::value_type value_type
size_t __TBB_EXPORTED_FUNC NFS_GetLineSize()
Cache/sector line size.
cache_aligned_allocator(const cache_aligned_allocator &)
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:309
void *__TBB_EXPORTED_FUNC NFS_Allocate(size_t n_element, size_t element_size, void *hint)
Allocate memory on cache/sector line boundary.
void destroy(pointer p)
Destroy value at location pointed to by p.
The graph class.
bool operator!=(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
pointer allocate(size_type n, const void *hint=0)
Allocate space for n objects, starting on a cache/sector line.
cache_aligned_allocator(const cache_aligned_allocator< U > &)
void construct(U *p, Args &&... args)
Copy-construct value at location pointed to by p.

Copyright © 2005-2018 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.