Intel(R) Threading Building Blocks Doxygen Documentation version 4.2.3
Loading...
Searching...
No Matches
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
27namespace tbb {
28
30namespace 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
57template<typename T>
59public:
62 typedef const value_type* const_pointer;
65 typedef size_t size_type;
66 typedef ptrdiff_t difference_type;
67 template<typename U> struct rebind {
69 };
70
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;}
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
127template<>
129public:
130 typedef void* pointer;
131 typedef const void* const_pointer;
132 typedef void value_type;
133 template<typename U> struct rebind {
135 };
136};
137
138template<typename T, typename U>
139inline bool operator==( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return true;}
140
141template<typename T, typename U>
142inline bool operator!=( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return false;}
143
145
150template <typename T, template<typename X> class Allocator = tbb_allocator>
151class zero_allocator : public Allocator<T>
152{
153public:
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() { }
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
180template<template<typename T> class Allocator>
181class zero_allocator<void, Allocator> : public Allocator<void> {
182public:
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
192template<typename T1, template<typename X1> class B1, typename T2, template<typename X2> class B2>
194 return static_cast< B1<T1> >(a) == static_cast< B2<T2> >(b);
195}
196template<typename T1, template<typename X1> class B1, typename T2, template<typename X2> class B2>
198 return static_cast< B1<T1> >(a) != static_cast< B2<T2> >(b);
199}
200
201} // namespace tbb
202
203#endif /* __TBB_tbb_allocator_H */
#define __TBB_EXPORTED_FUNC
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 const char const char int ITT_FORMAT __itt_group_sync p
The graph class.
bool operator==(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
bool operator!=(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
T max(const T &val1, const T &val2)
Utility template function returning greater of the two values.
Definition: tbb_misc.h:119
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
bool __TBB_EXPORTED_FUNC is_malloc_used_v3()
Returns true if standard malloc/free are used to work with memory.
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
Definition: tbb_allocator.h:58
const_pointer address(const_reference x) const
Definition: tbb_allocator.h:82
const value_type & const_reference
Definition: tbb_allocator.h:64
internal::allocator_type< T >::value_type value_type
Definition: tbb_allocator.h:60
void deallocate(pointer p, size_type)
Free previously allocated block of memory.
Definition: tbb_allocator.h:90
value_type * pointer
Definition: tbb_allocator.h:61
value_type & reference
Definition: tbb_allocator.h:63
malloc_type
Specifies current allocator.
Definition: tbb_allocator.h:72
const value_type * const_pointer
Definition: tbb_allocator.h:62
void construct(U *p, Args &&... args)
Copy-construct value at location pointed to by p.
tbb_allocator(const tbb_allocator &)
Definition: tbb_allocator.h:78
tbb_allocator(const tbb_allocator< U > &)
Definition: tbb_allocator.h:79
static malloc_type allocator_type()
Returns current allocator.
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.
ptrdiff_t difference_type
Definition: tbb_allocator.h:66
pointer address(reference x) const
Definition: tbb_allocator.h:81
pointer allocate(size_type n, const void *=0)
Allocate space for n objects.
Definition: tbb_allocator.h:85
tbb_allocator< U > other
Definition: tbb_allocator.h:68
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
base_allocator_type::reference reference
pointer allocate(const size_type n, const void *hint=0)
base_allocator_type::const_reference const_reference
base_allocator_type::const_pointer const_pointer
Allocator< T > base_allocator_type
base_allocator_type::size_type size_type
base_allocator_type::value_type value_type
zero_allocator(const zero_allocator &a)
zero_allocator(const zero_allocator< U > &a)
base_allocator_type::difference_type difference_type
base_allocator_type::pointer pointer
zero_allocator< U, Allocator > other
base_allocator_type::const_pointer const_pointer
base_allocator_type::value_type value_type
base_allocator_type::pointer pointer
zero_allocator< U, Allocator > other

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.