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-2019 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_tbb_allocator_H
22 #define __TBB_tbb_allocator_H
23 
24 #include "tbb_stddef.h"
25 #include <new>
26 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
27  #include <utility> // std::forward
28 #endif
29 #include <cstring>
30 
31 namespace tbb {
32 
34 namespace internal {
35 
37 
39 
41 
43 
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 
61 template<typename T>
63 public:
65  typedef value_type* pointer;
66  typedef const value_type* const_pointer;
68  typedef const value_type& const_reference;
69  typedef size_t size_type;
70  typedef ptrdiff_t difference_type;
71  template<typename U> struct rebind {
73  };
74 
76  enum malloc_type {
79  };
80 
81  tbb_allocator() throw() {}
82  tbb_allocator( const tbb_allocator& ) throw() {}
83  template<typename U> tbb_allocator(const tbb_allocator<U>&) throw() {}
84 
85  pointer address(reference x) const {return &x;}
86  const_pointer address(const_reference x) const {return &x;}
87 
89  pointer allocate( size_type n, const void* /*hint*/ = 0) {
91  }
92 
96  }
97 
99  size_type max_size() const throw() {
100  size_type max = static_cast<size_type>(-1) / sizeof (value_type);
101  return (max > 0 ? max : 1);
102  }
103 
105 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
106  template<typename U, typename... Args>
107  void construct(U *p, Args&&... args)
108  { ::new((void *)p) U(std::forward<Args>(args)...); }
109 #else // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
110 #if __TBB_CPP11_RVALUE_REF_PRESENT
111  void construct( pointer p, value_type&& value ) {::new((void*)(p)) value_type(std::move(value));}
112 #endif
113  void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);}
114 #endif // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
115 
117  void destroy( pointer p ) {p->~value_type();}
118 
122  }
123 };
124 
125 #if _MSC_VER && !defined(__INTEL_COMPILER)
126  #pragma warning (pop)
127 #endif // warning 4100 is back
128 
130 
131 template<>
133 public:
134  typedef void* pointer;
135  typedef const void* const_pointer;
136  typedef void value_type;
137  template<typename U> struct rebind {
139  };
140 };
141 
142 template<typename T, typename U>
143 inline bool operator==( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return true;}
144 
145 template<typename T, typename U>
146 inline bool operator!=( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return false;}
147 
149 
154 template <typename T, template<typename X> class Allocator = tbb_allocator>
155 class zero_allocator : public Allocator<T>
156 {
157 public:
158  typedef Allocator<T> base_allocator_type;
159  typedef typename base_allocator_type::value_type value_type;
160  typedef typename base_allocator_type::pointer pointer;
161  typedef typename base_allocator_type::const_pointer const_pointer;
162  typedef typename base_allocator_type::reference reference;
163  typedef typename base_allocator_type::const_reference const_reference;
164  typedef typename base_allocator_type::size_type size_type;
165  typedef typename base_allocator_type::difference_type difference_type;
166  template<typename U> struct rebind {
168  };
169 
170  zero_allocator() throw() { }
171  zero_allocator(const zero_allocator &a) throw() : base_allocator_type( a ) { }
172  template<typename U>
173  zero_allocator(const zero_allocator<U> &a) throw() : base_allocator_type( Allocator<U>( a ) ) { }
174 
175  pointer allocate(const size_type n, const void *hint = 0 ) {
176  pointer ptr = base_allocator_type::allocate( n, hint );
177  std::memset( static_cast<void*>(ptr), 0, n * sizeof(value_type) );
178  return ptr;
179  }
180 };
181 
183 
184 template<template<typename T> class Allocator>
185 class zero_allocator<void, Allocator> : public Allocator<void> {
186 public:
187  typedef Allocator<void> base_allocator_type;
188  typedef typename base_allocator_type::value_type value_type;
189  typedef typename base_allocator_type::pointer pointer;
190  typedef typename base_allocator_type::const_pointer const_pointer;
191  template<typename U> struct rebind {
193  };
194 };
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 template<typename T1, template<typename X1> class B1, typename T2, template<typename X2> class B2>
201 inline bool operator!=( const zero_allocator<T1,B1> &a, const zero_allocator<T2,B2> &b) {
202  return static_cast< B1<T1> >(a) != static_cast< B2<T2> >(b);
203 }
204 
205 } // namespace tbb
206 
207 #endif /* __TBB_tbb_allocator_H */
base_allocator_type::pointer pointer
bool operator==(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
tbb_allocator(const tbb_allocator &)
Definition: tbb_allocator.h:82
const value_type & const_reference
Definition: tbb_allocator.h:68
zero_allocator< U, Allocator > other
malloc_type
Specifies current allocator.
Definition: tbb_allocator.h:76
base_allocator_type::size_type size_type
value_type & reference
Definition: tbb_allocator.h:67
value_type * pointer
Definition: tbb_allocator.h:65
base_allocator_type::value_type value_type
tbb_allocator(const tbb_allocator< U > &)
Definition: tbb_allocator.h:83
ptrdiff_t difference_type
Definition: tbb_allocator.h:70
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
Definition: tbb_allocator.h:62
static malloc_type allocator_type()
Returns current allocator.
base_allocator_type::const_reference const_reference
size_type max_size() const
Largest value for which method allocate might succeed.
Definition: tbb_allocator.h:99
zero_allocator< U, Allocator > other
const value_type * const_pointer
Definition: tbb_allocator.h:66
zero_allocator(const zero_allocator< U > &a)
internal::allocator_type< T >::value_type value_type
Definition: tbb_allocator.h:64
base_allocator_type::const_pointer const_pointer
void const char const char int ITT_FORMAT __itt_group_sync p
base_allocator_type::reference reference
T max(const T &val1, const T &val2)
Utility template function returning greater of the two values.
Definition: tbb_misc.h:116
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
void destroy(pointer p)
Destroy value at location pointed to by p.
The graph class.
base_allocator_type::difference_type difference_type
pointer allocate(size_type n, const void *=0)
Allocate space for n objects.
Definition: tbb_allocator.h:89
const_pointer address(const_reference x) const
Definition: tbb_allocator.h:86
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
base_allocator_type::value_type value_type
void deallocate(pointer p, size_type)
Free previously allocated block of memory.
Definition: tbb_allocator.h:94
zero_allocator(const zero_allocator &a)
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
#define __TBB_EXPORTED_FUNC
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:309
bool operator!=(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
bool __TBB_EXPORTED_FUNC is_malloc_used_v3()
Returns true if standard malloc/free are used to work with memory.
base_allocator_type::pointer pointer
Allocator< T > base_allocator_type
pointer address(reference x) const
Definition: tbb_allocator.h:85
pointer allocate(const size_type n, const void *hint=0)
tbb_allocator< U > other
Definition: tbb_allocator.h:72
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
base_allocator_type::const_pointer const_pointer
void construct(U *p, Args &&... args)
Copy-construct value at location pointed to by p.

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