The Gaudi Framework  master (37c0b60a)
Gaudi::Allocator::Arena< Resource, T, DefaultResource > Class Template Reference

Custom allocator holding a pointer to a generic memory resource. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/Gaudi/Allocator/Arena.h>

Classes

struct  rebind
 

Public Types

using value_type = T
 
using propagate_on_container_swap = std::true_type
 
using propagate_on_container_copy_assignment = std::true_type
 
using propagate_on_container_move_assignment = std::true_type
 

Public Member Functions

constexpr Arena (Resource *resource) noexcept
 Construct an allocator using the given memory resource, which must be valid. More...
 
template<typename D = void, typename = std::enable_if_t<std::is_invocable_r_v<Resource*, DefaultResource>, D>>
 Arena ()
 Construct an allocator using the resource provided by DefaultResource. More...
 
template<typename U >
constexpr Arena (Arena< Resource, U, DefaultResource > const &other) noexcept
 Converting copy constructor, rebinding U -> T. More...
 
T * allocate (std::size_t n)
 Allocate storage for n objects. More...
 
void deallocate (T *p, std::size_t n) noexcept
 Deallocate storage for n objects. More...
 
Resource * resource () const noexcept
 Return a pointer to the memory resource. More...
 

Private Attributes

Resource * m_resource { nullptr }
 

Friends

template<typename , typename , typename >
struct Arena
 
template<typename U >
constexpr friend bool operator== (Arena const &lhs, Arena< Resource, U, DefaultResource > const &rhs)
 

Detailed Description

template<typename Resource, typename T, typename DefaultResource = void>
class Gaudi::Allocator::Arena< Resource, T, DefaultResource >

Custom allocator holding a pointer to a generic memory resource.

Custom allocator holding a pointer to a memory resource ("arena"). Allocation and deallocation requests are passed through to the arena. Note that the typedefs propagate_on_container_{swap,copy_assignment,move_assignment} do not have their default values.

The, optional, third template parameter (DefaultResource) may be used to specify a default arena, in which case the allocator is default-constructible. Otherwise, a pointer to an arena must be given.

Definition at line 29 of file Arena.h.

Member Typedef Documentation

◆ propagate_on_container_copy_assignment

template<typename Resource , typename T , typename DefaultResource = void>
using Gaudi::Allocator::Arena< Resource, T, DefaultResource >::propagate_on_container_copy_assignment = std::true_type

Definition at line 32 of file Arena.h.

◆ propagate_on_container_move_assignment

template<typename Resource , typename T , typename DefaultResource = void>
using Gaudi::Allocator::Arena< Resource, T, DefaultResource >::propagate_on_container_move_assignment = std::true_type

Definition at line 33 of file Arena.h.

◆ propagate_on_container_swap

template<typename Resource , typename T , typename DefaultResource = void>
using Gaudi::Allocator::Arena< Resource, T, DefaultResource >::propagate_on_container_swap = std::true_type

Definition at line 31 of file Arena.h.

◆ value_type

template<typename Resource , typename T , typename DefaultResource = void>
using Gaudi::Allocator::Arena< Resource, T, DefaultResource >::value_type = T

Definition at line 30 of file Arena.h.

Constructor & Destructor Documentation

◆ Arena() [1/3]

template<typename Resource , typename T , typename DefaultResource = void>
constexpr Gaudi::Allocator::Arena< Resource, T, DefaultResource >::Arena ( Resource *  resource)
inlineconstexprnoexcept

Construct an allocator using the given memory resource, which must be valid.

Definition at line 37 of file Arena.h.

37 : m_resource{ resource } {}

◆ Arena() [2/3]

template<typename Resource , typename T , typename DefaultResource = void>
template<typename D = void, typename = std::enable_if_t<std::is_invocable_r_v<Resource*, DefaultResource>, D>>
Gaudi::Allocator::Arena< Resource, T, DefaultResource >::Arena ( )
inline

Construct an allocator using the resource provided by DefaultResource.

This constructor is only enabled if an instance of DefaultResource can be invoked with no arguments and yields Resource*.

Definition at line 44 of file Arena.h.

44 : Arena( std::invoke( DefaultResource{} ) ) {}

◆ Arena() [3/3]

template<typename Resource , typename T , typename DefaultResource = void>
template<typename U >
constexpr Gaudi::Allocator::Arena< Resource, T, DefaultResource >::Arena ( Arena< Resource, U, DefaultResource > const &  other)
inlineconstexprnoexcept

Converting copy constructor, rebinding U -> T.

Definition at line 49 of file Arena.h.

49 : m_resource{ other.m_resource } {}

Member Function Documentation

◆ allocate()

template<typename Resource , typename T , typename DefaultResource = void>
T* Gaudi::Allocator::Arena< Resource, T, DefaultResource >::allocate ( std::size_t  n)
inline

Allocate storage for n objects.

Definition at line 53 of file Arena.h.

53  {
54  return reinterpret_cast<T*>( m_resource->template allocate<alignof( T )>( n * sizeof( T ) ) );
55  }

◆ deallocate()

template<typename Resource , typename T , typename DefaultResource = void>
void Gaudi::Allocator::Arena< Resource, T, DefaultResource >::deallocate ( T *  p,
std::size_t  n 
)
inlinenoexcept

Deallocate storage for n objects.

Definition at line 59 of file Arena.h.

59  {
60  m_resource->deallocate( reinterpret_cast<std::byte*>( p ), n * sizeof( T ) );
61  }

◆ resource()

template<typename Resource , typename T , typename DefaultResource = void>
Resource* Gaudi::Allocator::Arena< Resource, T, DefaultResource >::resource ( ) const
inlinenoexcept

Return a pointer to the memory resource.

Definition at line 65 of file Arena.h.

65 { return m_resource; }

Friends And Related Function Documentation

◆ Arena

template<typename Resource , typename T , typename DefaultResource = void>
template<typename , typename , typename >
friend struct Arena
friend

Definition at line 80 of file Arena.h.

◆ operator==

template<typename Resource , typename T , typename DefaultResource = void>
template<typename U >
constexpr friend bool operator== ( Arena< Resource, T, DefaultResource > const &  lhs,
Arena< Resource, U, DefaultResource > const &  rhs 
)
friend

Definition at line 68 of file Arena.h.

68  {
69  return lhs.m_resource == rhs.m_resource;
70  }

Member Data Documentation

◆ m_resource

template<typename Resource , typename T , typename DefaultResource = void>
Resource* Gaudi::Allocator::Arena< Resource, T, DefaultResource >::m_resource { nullptr }
private

Definition at line 82 of file Arena.h.


The documentation for this class was generated from the following file:
Gaudi::Allocator::Arena::Arena
friend struct Arena
Definition: Arena.h:80
cpluginsvc.n
n
Definition: cpluginsvc.py:234
Gaudi::Allocator::Arena::resource
Resource * resource() const noexcept
Return a pointer to the memory resource.
Definition: Arena.h:65
Gaudi::Allocator::Arena::m_resource
Resource * m_resource
Definition: Arena.h:82