ATLAS Offline Software
Loading...
Searching...
No Matches
ArenaBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
13
17#include <ostream>
18#include <print>
19
20
21namespace SG {
22
23
28ArenaBase::ArenaBase (const std::string& name /*= ""*/)
29 : m_name (name)
30{
31}
32
33
40
41
46{
47 lock_t l (m_mutex);
48 for (AllocEntry& alloc : m_allocs) {
49 if (alloc.m_alloc) {
50 lock_t alloc_lock (*alloc.m_mutex);
51 alloc.m_alloc->reset();
52 }
53 }
54}
55
56
62{
63 lock_t l (m_mutex);
64 for (AllocEntry& alloc : m_allocs) {
65 if (alloc.m_alloc) {
66 lock_t alloc_lock (*alloc.m_mutex);
67 alloc.m_alloc->erase();
68 }
69 }
70}
71
72
77void ArenaBase::report (std::ostream& os) const
78{
79 lock_t l (m_mutex);
80 bool first = true;
81 for (const AllocEntry& alloc : m_allocs) {
82 if (alloc.m_alloc) {
83 if (first) {
85 std::println (os);
86 first = false;
87 }
88 lock_t alloc_lock (*alloc.m_mutex);
89 alloc.m_alloc->report (os);
90 }
91 }
92}
93
94
99{
101 lock_t l (m_mutex);
102 for (const AllocEntry& alloc : m_allocs) {
103 if (alloc.m_alloc) {
104 lock_t alloc_lock (*alloc.m_mutex);
105 stats += alloc.m_alloc->stats();
106 }
107 }
108 return stats;
109}
110
111
115const std::string& ArenaBase::name() const
116{
117 return m_name;
118}
119
120
132{
133 // We have to create a new Allocator.
134 // Make sure there's room in the vector.
135 if (m_allocs.size() <= i) {
136 m_allocs.resize (i+1);
137 }
138
139 // Create the Allocator, using the Registry.
140 std::unique_ptr<ArenaAllocatorBase> alloc =
142
143 // Install it in the vector.
144 m_allocs[i].m_alloc = std::move (alloc);
145 m_allocs[i].m_mutex = std::make_unique<std::mutex>();
146
147 return m_allocs[i].m_alloc.get();
148}
149
150
151} // namespace SG
Common base class for arena allocator classes. See Arena.h for an overview of the arena-based memory ...
Registry of allocator factories. See Arena.h for an overview of the arena-based memory allocators.
Part of Arena dealing with the list of allocators. Broken out from Arena to avoid a dependency loop w...
Common base class for arena allocator classes.
std::unique_ptr< ArenaAllocatorBase > create(size_t i)
Create a new instance of an allocator.
static ArenaAllocatorRegistry * instance()
Return a pointer to the global ArenaAllocatorRegistry instance.
void reset()
Reset all contained allocators.
Definition ArenaBase.cxx:45
void report(std::ostream &os) const
Generate a report of the memory in use by this Arena.
Definition ArenaBase.cxx:77
ArenaAllocatorBase::Stats stats() const
Return statistics summed over all allocators in this Arena.
Definition ArenaBase.cxx:98
ArenaBase(const std::string &name="")
Constructor.
Definition ArenaBase.cxx:28
virtual ~ArenaBase()
Destructor.
Definition ArenaBase.cxx:37
std::lock_guard< std::mutex > lock_t
Definition ArenaBase.h:102
const std::string & name() const
Return this Arena's name.
void erase()
Erase all contained allocators.
Definition ArenaBase.cxx:61
std::mutex m_mutex
To guard access to m_allocs.
Definition ArenaBase.h:130
std::string m_name
Our name.
Definition ArenaBase.h:127
ArenaAllocatorBase * makeAllocator(size_t i)
Make a new Allocator for index i.
std::vector< AllocEntry > m_allocs
Definition ArenaBase.h:124
Forward declaration.
Statistics for an allocator.
static void header(std::ostream &os)
Print report header.
Our allocator vector.
Definition ArenaBase.h:120