tbb_allocator.h
Go to the documentation of this file.
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __TBB_tbb_allocator_H
#define __TBB_tbb_allocator_H
#include "tbb_stddef.h"
#include <new>
#if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
#include <utility> // std::forward
#endif
#include <cstring>
namespace tbb {
namespace internal {
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3( void *p );
void* __TBB_EXPORTED_FUNC allocate_via_handler_v3( size_t n );
bool __TBB_EXPORTED_FUNC is_malloc_used_v3();
}
#if _MSC_VER && !defined(__INTEL_COMPILER)
// Workaround for erroneous "unreferenced parameter" warning in method destroy.
#pragma warning (push)
#pragma warning (disable: 4100)
#endif
template<typename T>
class tbb_allocator {
public:
typedef typename internal::allocator_type<T>::value_type value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
template<typename U> struct rebind {
typedef tbb_allocator<U> other;
};
enum malloc_type {
scalable,
standard
};
tbb_allocator() throw() {}
tbb_allocator( const tbb_allocator& ) throw() {}
template<typename U> tbb_allocator(const tbb_allocator<U>&) throw() {}
pointer address(reference x) const {return &x;}
const_pointer address(const_reference x) const {return &x;}
pointer allocate( size_type n, const void* /*hint*/ = 0) {
return pointer(internal::allocate_via_handler_v3( n * sizeof(value_type) ));
}
void deallocate( pointer p, size_type ) {
internal::deallocate_via_handler_v3(p);
}
size_type max_size() const throw() {
size_type max = static_cast<size_type>(-1) / sizeof (value_type);
return (max > 0 ? max : 1);
}
#if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
template<typename U, typename... Args>
void construct(U *p, Args&&... args)
{ ::new((void *)p) U(std::forward<Args>(args)...); }
#else // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
#if __TBB_CPP11_RVALUE_REF_PRESENT
void construct( pointer p, value_type&& value ) {::new((void*)(p)) value_type(std::move(value));}
#endif
void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);}
#endif // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
void destroy( pointer p ) {p->~value_type();}
static malloc_type allocator_type() {
return internal::is_malloc_used_v3() ? standard : scalable;
}
};
#if _MSC_VER && !defined(__INTEL_COMPILER)
#pragma warning (pop)
#endif // warning 4100 is back
template<>
class tbb_allocator<void> {
public:
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
template<typename U> struct rebind {
typedef tbb_allocator<U> other;
};
};
template<typename T, typename U>
inline bool operator==( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return true;}
template<typename T, typename U>
inline bool operator!=( const tbb_allocator<T>&, const tbb_allocator<U>& ) {return false;}
template <typename T, template<typename X> class Allocator = tbb_allocator>
class zero_allocator : public Allocator<T>
{
public:
typedef Allocator<T> base_allocator_type;
typedef typename base_allocator_type::value_type value_type;
typedef typename base_allocator_type::pointer pointer;
typedef typename base_allocator_type::const_pointer const_pointer;
typedef typename base_allocator_type::reference reference;
typedef typename base_allocator_type::const_reference const_reference;
typedef typename base_allocator_type::size_type size_type;
typedef typename base_allocator_type::difference_type difference_type;
template<typename U> struct rebind {
typedef zero_allocator<U, Allocator> other;
};
zero_allocator() throw() { }
zero_allocator(const zero_allocator &a) throw() : base_allocator_type( a ) { }
template<typename U>
zero_allocator(const zero_allocator<U> &a) throw() : base_allocator_type( Allocator<U>( a ) ) { }
pointer allocate(const size_type n, const void *hint = 0 ) {
pointer ptr = base_allocator_type::allocate( n, hint );
std::memset( static_cast<void*>(ptr), 0, n * sizeof(value_type) );
return ptr;
}
};
template<template<typename T> class Allocator>
class zero_allocator<void, Allocator> : public Allocator<void> {
public:
typedef Allocator<void> base_allocator_type;
typedef typename base_allocator_type::value_type value_type;
typedef typename base_allocator_type::pointer pointer;
typedef typename base_allocator_type::const_pointer const_pointer;
template<typename U> struct rebind {
typedef zero_allocator<U, Allocator> other;
};
};
template<typename T1, template<typename X1> class B1, typename T2, template<typename X2> class B2>
inline bool operator==( const zero_allocator<T1,B1> &a, const zero_allocator<T2,B2> &b) {
return static_cast< B1<T1> >(a) == static_cast< B2<T2> >(b);
}
template<typename T1, template<typename X1> class B1, typename T2, template<typename X2> class B2>
inline bool operator!=( const zero_allocator<T1,B1> &a, const zero_allocator<T2,B2> &b) {
return static_cast< B1<T1> >(a) != static_cast< B2<T2> >(b);
}
} // namespace tbb
#endif /* __TBB_tbb_allocator_H */
tbb::tbb_allocator< void >::pointer
void * pointer
Definition: tbb_allocator.h:130
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::zero_allocator::base_allocator_type
Allocator< T > base_allocator_type
Definition: tbb_allocator.h:154
tbb::tbb_allocator::allocate
pointer allocate(size_type n, const void *=0)
Allocate space for n objects.
Definition: tbb_allocator.h:85
internal
Definition: _flow_graph_async_msg_impl.h:24
void
void
Definition: ittnotify_static.h:91
tbb::tbb_allocator::construct
void construct(U *p, Args &&... args)
Copy-construct value at location pointed to by p.
Definition: tbb_allocator.h:103
tbb::tbb_allocator::const_reference
const typedef value_type & const_reference
Definition: tbb_allocator.h:64
tbb::zero_allocator
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
Definition: tbb_allocator.h:151
tbb::tbb_allocator::max_size
size_type max_size() const
Largest value for which method allocate might succeed.
Definition: tbb_allocator.h:95
tbb::tbb_allocator::const_pointer
const typedef value_type * const_pointer
Definition: tbb_allocator.h:62
tbb::zero_allocator::value_type
base_allocator_type::value_type value_type
Definition: tbb_allocator.h:155
tbb::tbb_allocator::address
pointer address(reference x) const
Definition: tbb_allocator.h:81
tbb::zero_allocator::zero_allocator
zero_allocator(const zero_allocator &a)
Definition: tbb_allocator.h:167
tbb::tbb_allocator
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
Definition: tbb_allocator.h:58
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::tbb_allocator::difference_type
ptrdiff_t difference_type
Definition: tbb_allocator.h:66
tbb::operator!=
bool operator!=(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
Definition: cache_aligned_allocator.h:132
tbb::zero_allocator::size_type
base_allocator_type::size_type size_type
Definition: tbb_allocator.h:160
tbb::tbb_allocator::address
const_pointer address(const_reference x) const
Definition: tbb_allocator.h:82
tbb::zero_allocator< void, Allocator >::base_allocator_type
Allocator< void > base_allocator_type
Definition: tbb_allocator.h:183
tbb::zero_allocator< void, Allocator >::value_type
base_allocator_type::value_type value_type
Definition: tbb_allocator.h:184
tbb::tbb_allocator::standard
Definition: tbb_allocator.h:74
tbb::zero_allocator< void, Allocator >::pointer
base_allocator_type::pointer pointer
Definition: tbb_allocator.h:185
tbb::zero_allocator::const_reference
base_allocator_type::const_reference const_reference
Definition: tbb_allocator.h:159
tbb::tbb_allocator::deallocate
void deallocate(pointer p, size_type)
Free previously allocated block of memory.
Definition: tbb_allocator.h:90
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::zero_allocator::difference_type
base_allocator_type::difference_type difference_type
Definition: tbb_allocator.h:161
tbb::zero_allocator::zero_allocator
zero_allocator()
Definition: tbb_allocator.h:166
tbb::tbb_allocator::rebind
Definition: tbb_allocator.h:67
tbb::zero_allocator< void, Allocator >::rebind::other
zero_allocator< U, Allocator > other
Definition: tbb_allocator.h:188
tbb::tbb_allocator::value_type
internal::allocator_type< T >::value_type value_type
Definition: tbb_allocator.h:60
tbb::zero_allocator::reference
base_allocator_type::reference reference
Definition: tbb_allocator.h:158
tbb::tbb_allocator::malloc_type
malloc_type
Specifies current allocator.
Definition: tbb_allocator.h:72
tbb::tbb_allocator::destroy
void destroy(pointer p)
Destroy value at location pointed to by p.
Definition: tbb_allocator.h:113
tbb::tbb_allocator< void >::value_type
void value_type
Definition: tbb_allocator.h:132
tbb::tbb_allocator::pointer
value_type * pointer
Definition: tbb_allocator.h:61
tbb::tbb_allocator::scalable
Definition: tbb_allocator.h:73
tbb::tbb_allocator::reference
value_type & reference
Definition: tbb_allocator.h:63
tbb::tbb_allocator::size_type
size_t size_type
Definition: tbb_allocator.h:65
tbb::zero_allocator::pointer
base_allocator_type::pointer pointer
Definition: tbb_allocator.h:156
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::zero_allocator< void, Allocator >::const_pointer
base_allocator_type::const_pointer const_pointer
Definition: tbb_allocator.h:186
tbb::tbb_allocator< void >::rebind::other
tbb_allocator< U > other
Definition: tbb_allocator.h:134
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::tbb_allocator
tbb_allocator(const tbb_allocator &)
Definition: tbb_allocator.h:78
tbb::tbb_allocator::tbb_allocator
tbb_allocator()
Definition: tbb_allocator.h:77
tbb::tbb_allocator::tbb_allocator
tbb_allocator(const tbb_allocator< U > &)
Definition: tbb_allocator.h:79
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::rebind
Definition: tbb_allocator.h:162
tbb_stddef.h
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
tbb::zero_allocator::const_pointer
base_allocator_type::const_pointer const_pointer
Definition: tbb_allocator.h:157
tbb::zero_allocator::zero_allocator
zero_allocator(const zero_allocator< U > &a)
Definition: tbb_allocator.h:169
tbb::internal::allocator_type::value_type
T value_type
Definition: tbb_stddef.h:472
tbb::tbb_allocator::allocator_type
static malloc_type allocator_type()
Returns current allocator.
Definition: tbb_allocator.h:116
tbb::tbb_allocator< void >::const_pointer
const typedef void * const_pointer
Definition: tbb_allocator.h:131
tbb::zero_allocator::allocate
pointer allocate(const size_type n, const void *hint=0)
Definition: tbb_allocator.h:171
tbb::zero_allocator::rebind::other
zero_allocator< U, Allocator > other
Definition: tbb_allocator.h:163
tbb::tbb_allocator::rebind::other
tbb_allocator< U > other
Definition: tbb_allocator.h:68
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.