Warning, file /include/oneapi/tbb/tbb_allocator.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef __TBB_tbb_allocator_H
0018 #define __TBB_tbb_allocator_H
0019
0020 #include "oneapi/tbb/detail/_utils.h"
0021 #include "detail/_namespace_injection.h"
0022 #include <cstdlib>
0023 #include <utility>
0024
0025 #if __TBB_CPP17_MEMORY_RESOURCE_PRESENT
0026 #include <memory_resource>
0027 #endif
0028
0029 namespace tbb {
0030 namespace detail {
0031
0032 namespace r1 {
0033 TBB_EXPORT void* __TBB_EXPORTED_FUNC allocate_memory(std::size_t size);
0034 TBB_EXPORT void __TBB_EXPORTED_FUNC deallocate_memory(void* p);
0035 TBB_EXPORT bool __TBB_EXPORTED_FUNC is_tbbmalloc_used();
0036 }
0037
0038 namespace d1 {
0039
0040 template<typename T>
0041 class tbb_allocator {
0042 public:
0043 using value_type = T;
0044 using propagate_on_container_move_assignment = std::true_type;
0045
0046
0047 using is_always_equal = std::true_type;
0048
0049
0050 enum malloc_type {
0051 scalable,
0052 standard
0053 };
0054
0055 tbb_allocator() = default;
0056 template<typename U> tbb_allocator(const tbb_allocator<U>&) noexcept {}
0057
0058
0059 __TBB_nodiscard T* allocate(std::size_t n) {
0060 return static_cast<T*>(r1::allocate_memory(n * sizeof(value_type)));
0061 }
0062
0063
0064 void deallocate(T* p, std::size_t) {
0065 r1::deallocate_memory(p);
0066 }
0067
0068
0069 static malloc_type allocator_type() {
0070 return r1::is_tbbmalloc_used() ? standard : scalable;
0071 }
0072
0073 #if TBB_ALLOCATOR_TRAITS_BROKEN
0074 using pointer = value_type*;
0075 using const_pointer = const value_type*;
0076 using reference = value_type&;
0077 using const_reference = const value_type&;
0078 using difference_type = std::ptrdiff_t;
0079 using size_type = std::size_t;
0080 template<typename U> struct rebind {
0081 using other = tbb_allocator<U>;
0082 };
0083
0084 size_type max_size() const noexcept {
0085 size_type max = ~(std::size_t(0)) / sizeof(value_type);
0086 return (max > 0 ? max : 1);
0087 }
0088 template<typename U, typename... Args>
0089 void construct(U *p, Args&&... args)
0090 { ::new (p) U(std::forward<Args>(args)...); }
0091 void destroy( pointer p ) { p->~value_type(); }
0092 pointer address(reference x) const { return &x; }
0093 const_pointer address(const_reference x) const { return &x; }
0094 #endif
0095 };
0096
0097 #if TBB_ALLOCATOR_TRAITS_BROKEN
0098 template<>
0099 class tbb_allocator<void> {
0100 public:
0101 using pointer = void*;
0102 using const_pointer = const void*;
0103 using value_type = void;
0104 template<typename U> struct rebind {
0105 using other = tbb_allocator<U>;
0106 };
0107 };
0108 #endif
0109
0110 template<typename T, typename U>
0111 inline bool operator==(const tbb_allocator<T>&, const tbb_allocator<U>&) noexcept { return true; }
0112
0113 #if !__TBB_CPP20_COMPARISONS_PRESENT
0114 template<typename T, typename U>
0115 inline bool operator!=(const tbb_allocator<T>&, const tbb_allocator<U>&) noexcept { return false; }
0116 #endif
0117
0118 }
0119 }
0120
0121 inline namespace v1 {
0122 using detail::d1::tbb_allocator;
0123 }
0124 }
0125
0126 #endif