1 #ifndef DASH__ALLOCATOR__GLOBAL_ALLOCATOR_H__INCLUDED 2 #define DASH__ALLOCATOR__GLOBAL_ALLOCATOR_H__INCLUDED 4 #include <dash/memory/MemorySpace.h> 12 typedef std::remove_cv_t<std::remove_reference_t<T>> type;
16 template <
class T,
class GlobMemType>
26 using value_type =
typename detail::remove_cvref<T>::type;
29 using pointer =
typename std::pointer_traits<
32 using memory_resource = GlobMemType;
37 memory_resource* memory_resource) noexcept
38 : m_resource(memory_resource)
44 : m_resource(other.resource())
48 pointer allocate(std::size_t n)
51 constexpr
bool is_contiguous = std::is_same<
52 typename memory_traits::memory_space_layout_tag,
54 pointer p = m_resource ?
static_cast<pointer
>(m_resource->allocate(
55 n *
sizeof(T),
alignof(T)))
57 if (is_contiguous && p) {
58 auto& reg = internal::MemorySpaceRegistry::GetInstance();
59 reg.add(static_cast<dart_gptr_t>(p), m_resource);
64 void deallocate(pointer p, std::size_t n)
67 constexpr
bool is_contiguous = std::is_same<
68 typename memory_traits::memory_space_layout_tag,
70 if (m_resource && p) {
71 m_resource->deallocate(p, n *
sizeof(T),
alignof(T));
73 auto& reg = internal::MemorySpaceRegistry::GetInstance();
74 reg.erase(static_cast<dart_gptr_t>(p));
79 memory_resource* resource()
const noexcept
85 memory_resource* m_resource{
nullptr};
88 template <
class T,
class GlobMemType>
89 constexpr
bool operator==(
99 return lhs.resource() == rhs.resource();
This class is a simple memory pool which holds allocates elements of size ValueType.