The Gaudi Framework
master (1a7a3838)
Toggle main menu visibility
Loading...
Searching...
No Matches
Arena.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 2019-20 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#pragma once
12
#include <cstddef>
13
#include <functional>
14
#include <type_traits>
15
namespace
Gaudi::Allocator
{
28
template
<
typename
Resource,
typename
T,
typename
DefaultResource =
void
>
29
struct
Arena
{
30
using
value_type
= T;
31
using
propagate_on_container_swap
= std::true_type;
32
using
propagate_on_container_copy_assignment
= std::true_type;
33
using
propagate_on_container_move_assignment
= std::true_type;
34
37
constexpr
Arena
( Resource*
resource
) noexcept :
m_resource
{
resource
} {}
38
43
template
<
typename
D =
void
>
44
requires
( std::is_invocable_r_v<Resource*, DefaultResource> )
45
Arena
() :
Arena
( std::invoke( DefaultResource{} ) ) {}
46
49
template
<
typename
U>
50
constexpr
Arena
(
Arena<Resource, U, DefaultResource>
const
& other ) noexcept :
m_resource
{ other.m_resource } {}
51
54
[[nodiscard]] T*
allocate
( std::size_t n ) {
55
return
reinterpret_cast<
T*
>
(
m_resource
->template
allocate<alignof( T )>
( n *
sizeof
( T ) ) );
56
}
57
60
void
deallocate
( T* p, std::size_t n )
noexcept
{
61
m_resource
->deallocate(
reinterpret_cast<
std::byte*
>
( p ), n *
sizeof
( T ) );
62
}
63
66
[[nodiscard]] Resource*
resource
() const noexcept {
return
m_resource
; }
67
68
template
<
typename
U>
69
friend
constexpr
bool
operator==
(
Arena
const
& lhs,
Arena<Resource, U, DefaultResource>
const
& rhs ) {
70
return
lhs.
m_resource
== rhs.
m_resource
;
71
}
72
73
template
<
typename
U>
74
struct
rebind
{
75
using
other
=
Arena<Resource, U, DefaultResource>
;
76
};
77
78
private
:
79
// Required for the Arena<Resource, U, DefaultResource> converting copy constructor
80
template
<
typename
,
typename
,
typename
>
81
friend
struct
Arena
;
82
83
Resource*
m_resource
{
nullptr
};
84
};
85
86
template
<
typename
Resource,
typename
T,
typename
U,
typename
DefaultResource>
87
inline
constexpr
bool
operator!=
(
Arena<Resource, T, DefaultResource>
const
& lhs,
88
Arena<Resource, U, DefaultResource>
const
& rhs ) {
89
return
!( lhs == rhs );
90
}
91
}
// namespace Gaudi::Allocator
Gaudi::Allocator
Definition
Arena.h:15
Gaudi::Allocator::operator!=
constexpr bool operator!=(Arena< Resource, T, DefaultResource > const &lhs, Arena< Resource, U, DefaultResource > const &rhs)
Definition
Arena.h:87
Gaudi::Allocator::Arena::rebind
Definition
Arena.h:74
Gaudi::Allocator::Arena::rebind::other
Arena< Resource, U, DefaultResource > other
Definition
Arena.h:75
Gaudi::Allocator::Arena
Custom allocator holding a pointer to a generic memory resource.
Definition
Arena.h:29
Gaudi::Allocator::Arena::operator==
friend constexpr bool operator==(Arena const &lhs, Arena< Resource, U, DefaultResource > const &rhs)
Definition
Arena.h:69
Gaudi::Allocator::Arena< Resource, U, DefaultResource >::resource
Resource * resource() const noexcept
Definition
Arena.h:66
Gaudi::Allocator::Arena::value_type
T value_type
Definition
Arena.h:30
Gaudi::Allocator::Arena< Resource, U, DefaultResource >::m_resource
Resource * m_resource
Definition
Arena.h:83
Gaudi::Allocator::Arena::Arena
friend struct Arena
Definition
Arena.h:81
Gaudi::Allocator::Arena::propagate_on_container_swap
std::true_type propagate_on_container_swap
Definition
Arena.h:31
Gaudi::Allocator::Arena::Arena
constexpr Arena(Resource *resource) noexcept
Construct an allocator using the given memory resource, which must be valid.
Definition
Arena.h:37
Gaudi::Allocator::Arena::Arena
constexpr Arena(Arena< Resource, U, DefaultResource > const &other) noexcept
Converting copy constructor, rebinding U -> T.
Definition
Arena.h:50
Gaudi::Allocator::Arena::Arena
Arena()
Construct an allocator using the resource provided by DefaultResource.
Definition
Arena.h:45
Gaudi::Allocator::Arena::allocate
T * allocate(std::size_t n)
Allocate storage for n objects.
Definition
Arena.h:54
Gaudi::Allocator::Arena::propagate_on_container_copy_assignment
std::true_type propagate_on_container_copy_assignment
Definition
Arena.h:32
Gaudi::Allocator::Arena::deallocate
void deallocate(T *p, std::size_t n) noexcept
Deallocate storage for n objects.
Definition
Arena.h:60
Gaudi::Allocator::Arena::propagate_on_container_move_assignment
std::true_type propagate_on_container_move_assignment
Definition
Arena.h:33
GaudiKernel
include
Gaudi
Allocator
Arena.h
Generated on
for The Gaudi Framework by
1.17.0