Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb_allocator.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2020 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 #ifndef __TBB_tbb_allocator_H
18 #define __TBB_tbb_allocator_H
19 
20 #include "tbb_stddef.h"
21 #include <new>
22 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
23  #include <utility> // std::forward
24 #endif
25 #include <cstring>
26 
27 namespace tbb {
28 
30 namespace internal {
31 
33 
35 
37 
39 
42 }
44 
45 #if _MSC_VER && !defined(__INTEL_COMPILER)
46  // Workaround for erroneous "unreferenced parameter" warning in method destroy.
47  #pragma warning (push)
48  #pragma warning (disable: 4100)
49 #endif
50 
52 
57 template<typename T>
59 public:
61  typedef value_type* pointer;
62  typedef const value_type* const_pointer;
64  typedef const value_type& const_reference;
65  typedef size_t size_type;
66  typedef ptrdiff_t difference_type;
67  template<typename U> struct rebind {
69  };
70 
72  enum malloc_type {
75  };
76 
77  tbb_allocator() throw() {}
78  tbb_allocator( const tbb_allocator& ) throw() {}
79  template<typename U> tbb_allocator(const tbb_allocator<U>&) throw() {}
80 
81  pointer address(reference x) const {return &x;}
82  const_pointer address(const_reference x) const {return &x;}
83 
85  pointer allocate( size_type n, const void* /*hint*/ = 0) {
87  }
88 
92  }
93 
95  size_type max_size() const throw() {
96  size_type max = static_cast<size_type>(-1) / sizeof (value_type);
97  return (max > 0 ? max : 1);
98  }
99 
101 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
102  template<typename U, typename... Args>
103  void construct(U *p, Args&&... args)
104  { ::new((void *)p) U(std::forward<Args>(args)...); }
105 #else // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
106 #if __TBB_CPP11_RVALUE_REF_PRESENT
107  void construct( pointer p, value_type&& value ) {::new((void*)(p)) value_type(std::move(value));}
108 #endif
109  void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);}
110 #endif // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
111 
113  void destroy( pointer p ) {p->~value_type();}
114 
118  }
119 };
120 
121 #if _MSC_VER && !defined(__INTEL_COMPILER)
122  #pragma warning (pop)
123 #endif // warning 4100 is back
124 
126 
127 template<>
129 public:
130  typedef void* pointer;
131  typedef const void* const_pointer;
132  typedef void value_type;
133  template<typename U> struct rebind {
135  };
136 };
137 
138 template<typename T, typename U>
139 inline bool operator==( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return true;}
140 
141 template<typename T, typename U>
142 inline bool operator!=( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return false;}
143 
145 
150 template <typename T, template<typename X> class Allocator = tbb_allocator>
151 class zero_allocator : public Allocator<T>
152 {
153 public:
154  typedef Allocator<T> base_allocator_type;
155  typedef typename base_allocator_type::value_type value_type;
156  typedef typename base_allocator_type::pointer pointer;
157  typedef typename base_allocator_type::const_pointer const_pointer;
158  typedef typename base_allocator_type::reference reference;
159  typedef typename base_allocator_type::const_reference const_reference;
160  typedef typename base_allocator_type::size_type size_type;
161  typedef typename base_allocator_type::difference_type difference_type;
162  template<typename U> struct rebind {
164  };
165 
166  zero_allocator() throw() { }
167  zero_allocator(const zero_allocator &a) throw() : base_allocator_type( a ) { }
168  template<typename U>
169  zero_allocator(const zero_allocator<U> &a) throw() : base_allocator_type( Allocator<U>( a ) ) { }
170 
171  pointer allocate(const size_type n, const void *hint = 0 ) {
172  pointer ptr = base_allocator_type::allocate( n, hint );
173  std::memset( static_cast<void*>(ptr), 0, n * sizeof(value_type) );
174  return ptr;
175  }
176 };
177 
179 
180 template<template<typename T> class Allocator>
181 class zero_allocator<void, Allocator> : public Allocator<void> {
182 public:
183  typedef Allocator<void> base_allocator_type;
184  typedef typename base_allocator_type::value_type value_type;
185  typedef typename base_allocator_type::pointer pointer;
186  typedef typename base_allocator_type::const_pointer const_pointer;
187  template<typename U> struct rebind {
189  };
190 };
191 
192 template<typename T1, template<typename X1> class B1, typename T2, template<typename X2> class B2>
193 inline bool operator==( const zero_allocator<T1,B1> &a, const zero_allocator<T2,B2> &b) {
194  return static_cast< B1<T1> >(a) == static_cast< B2<T2> >(b);
195 }
196 template<typename T1, template<typename X1> class B1, typename T2, template<typename X2> class B2>
197 inline bool operator!=( const zero_allocator<T1,B1> &a, const zero_allocator<T2,B2> &b) {
198  return static_cast< B1<T1> >(a) != static_cast< B2<T2> >(b);
199 }
200 
201 } // namespace tbb
202 
203 #endif /* __TBB_tbb_allocator_H */
tbb::tbb_allocator::construct
void construct(pointer p, value_type &&value)
Copy-construct value at location pointed to by p.
Definition: tbb_allocator.h:107
tbb::tbb_allocator::size_type
size_t size_type
Definition: tbb_allocator.h:65
tbb::tbb_allocator< void >::const_pointer
const typedef void * const_pointer
Definition: tbb_allocator.h:131
tbb::internal::deallocate_via_handler_v3
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
Definition: cache_aligned_allocator.cpp:232
tbb::tbb_allocator::difference_type
ptrdiff_t difference_type
Definition: tbb_allocator.h:66
tbb::tbb_allocator::const_pointer
const typedef value_type * const_pointer
Definition: tbb_allocator.h:62
tbb::zero_allocator< void, Allocator >::pointer
base_allocator_type::pointer pointer
Definition: tbb_allocator.h:185
internal
Definition: _flow_graph_async_msg_impl.h:24
void
void
Definition: ittnotify_static.h:91
tbb::zero_allocator::pointer
base_allocator_type::pointer pointer
Definition: tbb_allocator.h:156
tbb::tbb_allocator::allocator_type
static malloc_type allocator_type()
Returns current allocator.
Definition: tbb_allocator.h:116
tbb::tbb_allocator::malloc_type
malloc_type
Specifies current allocator.
Definition: tbb_allocator.h:72
tbb::tbb_allocator::rebind::other
tbb_allocator< U > other
Definition: tbb_allocator.h:68
tbb::tbb_allocator::construct
void construct(pointer p, const value_type &value)
Definition: tbb_allocator.h:109
tbb::tbb_allocator::deallocate
void deallocate(pointer p, size_type)
Free previously allocated block of memory.
Definition: tbb_allocator.h:90
tbb::tbb_allocator::reference
value_type & reference
Definition: tbb_allocator.h:63
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::zero_allocator::rebind
Definition: tbb_allocator.h:162
tbb::zero_allocator::const_reference
base_allocator_type::const_reference const_reference
Definition: tbb_allocator.h:159
tbb::zero_allocator::base_allocator_type
Allocator< T > base_allocator_type
Definition: tbb_allocator.h:154
tbb::operator!=
bool operator!=(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
Definition: cache_aligned_allocator.h:132
tbb::tbb_allocator::tbb_allocator
tbb_allocator(const tbb_allocator &)
Definition: tbb_allocator.h:78
tbb::tbb_allocator::destroy
void destroy(pointer p)
Destroy value at location pointed to by p.
Definition: tbb_allocator.h:113
tbb::tbb_allocator::standard
@ standard
Definition: tbb_allocator.h:74
tbb::zero_allocator::value_type
base_allocator_type::value_type value_type
Definition: tbb_allocator.h:155
tbb::tbb_allocator::tbb_allocator
tbb_allocator(const tbb_allocator< U > &)
Definition: tbb_allocator.h:79
tbb::zero_allocator< void, Allocator >::base_allocator_type
Allocator< void > base_allocator_type
Definition: tbb_allocator.h:183
tbb::zero_allocator< void, Allocator >::rebind::other
zero_allocator< U, Allocator > other
Definition: tbb_allocator.h:188
tbb::zero_allocator< void, Allocator >::const_pointer
base_allocator_type::const_pointer const_pointer
Definition: tbb_allocator.h:186
tbb::tbb_allocator::allocate
pointer allocate(size_type n, const void *=0)
Allocate space for n objects.
Definition: tbb_allocator.h:85
tbb::internal::allocator_type::value_type
T value_type
Definition: tbb_stddef.h:472
tbb::tbb_allocator::max_size
size_type max_size() const
Largest value for which method allocate might succeed.
Definition: tbb_allocator.h:95
tbb::zero_allocator::rebind::other
zero_allocator< U, Allocator > other
Definition: tbb_allocator.h:163
tbb::operator==
bool operator==(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
Definition: cache_aligned_allocator.h:129
tbb::move
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319
tbb::tbb_allocator
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
Definition: tbb_allocator.h:58
tbb::tbb_allocator::const_reference
const typedef value_type & const_reference
Definition: tbb_allocator.h:64
tbb::zero_allocator::allocate
pointer allocate(const size_type n, const void *hint=0)
Definition: tbb_allocator.h:171
tbb::zero_allocator::size_type
base_allocator_type::size_type size_type
Definition: tbb_allocator.h:160
tbb::zero_allocator::zero_allocator
zero_allocator()
Definition: tbb_allocator.h:166
tbb::tbb_allocator::value_type
internal::allocator_type< T >::value_type value_type
Definition: tbb_allocator.h:60
tbb::tbb_allocator< void >::pointer
void * pointer
Definition: tbb_allocator.h:130
tbb::tbb_allocator< void >::value_type
void value_type
Definition: tbb_allocator.h:132
tbb::internal::allocate_via_handler_v3
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
Definition: cache_aligned_allocator.cpp:224
__TBB_EXPORTED_FUNC
#define __TBB_EXPORTED_FUNC
Definition: scalable_allocator.h:38
tbb::tbb_allocator::pointer
value_type * pointer
Definition: tbb_allocator.h:61
tbb::zero_allocator::difference_type
base_allocator_type::difference_type difference_type
Definition: tbb_allocator.h:161
tbb::zero_allocator::const_pointer
base_allocator_type::const_pointer const_pointer
Definition: tbb_allocator.h:157
tbb::internal::max
T max(const T &val1, const T &val2)
Utility template function returning greater of the two values.
Definition: tbb_misc.h:119
tbb::tbb_allocator< void >::rebind::other
tbb_allocator< U > other
Definition: tbb_allocator.h:134
tbb::zero_allocator< void, Allocator >::value_type
base_allocator_type::value_type value_type
Definition: tbb_allocator.h:184
tbb::tbb_allocator::scalable
@ scalable
Definition: tbb_allocator.h:73
value
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
Definition: ittnotify_static.h:192
tbb::zero_allocator
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
Definition: tbb_allocator.h:151
tbb::tbb_allocator::rebind
Definition: tbb_allocator.h:67
tbb_stddef.h
tbb::tbb_allocator::tbb_allocator
tbb_allocator()
Definition: tbb_allocator.h:77
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
tbb::zero_allocator::reference
base_allocator_type::reference reference
Definition: tbb_allocator.h:158
tbb::zero_allocator::zero_allocator
zero_allocator(const zero_allocator< U > &a)
Definition: tbb_allocator.h:169
tbb::zero_allocator::zero_allocator
zero_allocator(const zero_allocator &a)
Definition: tbb_allocator.h:167
tbb::tbb_allocator::address
pointer address(reference x) const
Definition: tbb_allocator.h:81
tbb::tbb_allocator::address
const_pointer address(const_reference x) const
Definition: tbb_allocator.h:82
tbb::internal::is_malloc_used_v3
bool __TBB_EXPORTED_FUNC is_malloc_used_v3()
Returns true if standard malloc/free are used to work with memory.
Definition: cache_aligned_allocator.cpp:238

Copyright © 2005-2020 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.