ATLAS Offline Software
Loading...
Searching...
No Matches
ArenaAllocatorBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
11
13#include <ostream>
14#include <iomanip>
15
16
17namespace SG {
18
19
24 : inuse (0),
25 free (0),
26 total (0)
27{
28}
29
30
38
39
46{
47 inuse += other.inuse;
48 free += other.free;
49 total += other.total;
50 return *this;
51}
52
53
54/* (hide from doxygen)
55 * @brief Format a statistic structure.
56 * @param os The stream to which to write.
57 * @param stat The statistic structure to write.
58 */
59std::ostream& operator<< (std::ostream& os,
61{
62 std::print (os, "{}", stat);
63 return os;
64}
65
66
67//===========================================================================
68
69
74{
75 elts.clear();
76 bytes.clear();
77 blocks.clear();
78}
79
80
87{
88 elts += other.elts;
89 bytes += other.bytes;
90 blocks += other.blocks;
91 return *this;
92}
93
94
95/* (hide from doxygen)
96 * @brief Format a complete statistics structure.
97 * @param os The stream to which to write.
98 * @param stats The statistics structure to write.
99 */
100std::ostream& operator<< (std::ostream& os,
102{
103 std::print (os, "{}", stats);
104 return os;
105}
106
107
113{
114 std::print (os, "Elts InUse/Free/Total"
115 " Bytes InUse/Free/Total Blocks InUse/Free/Total");
116}
117
118
119//===========================================================================
120
121
126void ArenaAllocatorBase::report (std::ostream& os) const
127{
128 std::println (os, " {} {}", stats(), name());
129}
130
131
132} // namespace SG
133
134
136template <class FmtContext>
137typename FmtContext::iterator
138std::formatter<SG::ArenaAllocatorBase::Stats::Stat>::format (const SG::ArenaAllocatorBase::Stats::Stat& stat, FmtContext& ctx) const
139{
140 return std::format_to (ctx.out(), "{:7}/{:7}/{:7}", stat.inuse, stat.free, stat.total);
141}
142
143
145template <class FmtContext>
146typename FmtContext::iterator
147std::formatter<SG::ArenaAllocatorBase::Stats>::format (const SG::ArenaAllocatorBase::Stats& stats, FmtContext& ctx) const
148{
149 return std::format_to (ctx.out(), "{} {} {}", stats.elts, stats.bytes, stats.blocks);
150}
Common base class for arena allocator classes. See Arena.h for an overview of the arena-based memory ...
virtual const std::string & name() const =0
Return the name of this allocator.
virtual void report(std::ostream &os) const
Generate a report on the memory usage of this allocator.
virtual Stats stats() const =0
Return the statistics block for this allocator.
Forward declaration.
std::ostream & operator<<(std::ostream &os, const ArenaAllocatorBase::Stats::Stat &stat)
Format a statistic structure.
Stat & operator+=(const Stat &other)
Accumulate.
size_t free
Number of items currently not allocated by the application but cached by the allocator.
size_t inuse
Number of items currently allocated by the application.
size_t total
Total number of items held by the allocator.
Statistics for an allocator.
static void header(std::ostream &os)
Print report header.
Stats & operator+=(const Stats &other)
Accumulate.