Home ⌂Doc Index ◂Up ▴
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 */
pointer allocate(size_type n, const void *=0)
Allocate space for n objects.
Definition: tbb_allocator.h:85
base_allocator_type::pointer pointer
base_allocator_type::value_type value_type
const_pointer address(const_reference x) const
Definition: tbb_allocator.h:82
malloc_type
Specifies current allocator.
Definition: tbb_allocator.h:72
tbb_allocator< U > other
Definition: tbb_allocator.h:68
value_type & reference
Definition: tbb_allocator.h:63
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
void construct(U *p, Args &&... args)
Copy-construct value at location pointed to by p.
base_allocator_type::reference reference
bool operator!=(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
zero_allocator< U, Allocator > other
Allocator< T > base_allocator_type
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
base_allocator_type::const_pointer const_pointer
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
Definition: tbb_allocator.h:58
void const char const char int ITT_FORMAT __itt_group_sync p
#define __TBB_EXPORTED_FUNC
zero_allocator(const zero_allocator &a)
const value_type & const_reference
Definition: tbb_allocator.h:64
base_allocator_type::size_type size_type
base_allocator_type::const_reference const_reference
pointer address(reference x) const
Definition: tbb_allocator.h:81
ptrdiff_t difference_type
Definition: tbb_allocator.h:66
pointer allocate(const size_type n, const void *hint=0)
size_type max_size() const
Largest value for which method allocate might succeed.
Definition: tbb_allocator.h:95
void destroy(pointer p)
Destroy value at location pointed to by p.
value_type * pointer
Definition: tbb_allocator.h:61
base_allocator_type::pointer pointer
tbb_allocator(const tbb_allocator< U > &)
Definition: tbb_allocator.h:79
static malloc_type allocator_type()
Returns current allocator.
zero_allocator(const zero_allocator< U > &a)
zero_allocator< U, Allocator > other
T max(const T &val1, const T &val2)
Utility template function returning greater of the two values.
Definition: tbb_misc.h:119
void deallocate(pointer p, size_type)
Free previously allocated block of memory.
Definition: tbb_allocator.h:90
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
tbb_allocator(const tbb_allocator &)
Definition: tbb_allocator.h:78
base_allocator_type::const_pointer const_pointer
const value_type * const_pointer
Definition: tbb_allocator.h:62
The graph class.
internal::allocator_type< T >::value_type value_type
Definition: tbb_allocator.h:60
bool __TBB_EXPORTED_FUNC is_malloc_used_v3()
Returns true if standard malloc/free are used to work with memory.
base_allocator_type::value_type value_type
base_allocator_type::difference_type difference_type
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
bool operator==(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319

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.