ATLAS Offline Software
Loading...
Searching...
No Matches
ArenaPoolAllocator.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2/*
3 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4*/
12
13#ifndef ATHALLOCATORS_ARENAPOOLALLOCATOR_H
14#define ATHALLOCATORS_ARENAPOOLALLOCATOR_H
15
16
18#include "boost/iterator/iterator_adaptor.hpp"
19#include <cstdlib>
20
21
22namespace SG {
23
24
25class ArenaBlock;
26
27
40{
41public:
42 // Needed forward declaration.
43 class const_iterator;
44
54 : public boost::iterator_adaptor<
55 iterator,
56 pointer,
57 boost::use_default,
58 boost::forward_traversal_tag>
59 {
60 public:
65
66
73
74
75 // To allow initializing a @c const_iterator from an @c iterator.
76 friend class const_iterator;
77
78
79 private:
82
83 // Required by @c iterator_adaptor.
85
87 void increment();
88 };
89
90
100 : public boost::iterator_adaptor<
101 const_iterator,
102 const_pointer,
103 boost::use_default,
104 boost::forward_traversal_tag>
105 {
106 public:
111
112
119
120
126
127
128 private:
131
132 // Required by @c iterator_adaptor.
134
136 void increment();
137 };
138
139
146
147
151 virtual ~ArenaPoolAllocator();
152
153
157
158
163
164
169
170
174 void swap (ArenaPoolAllocator& other);
175
176
183
184
193 virtual void reset() override;
194
195
204 virtual void erase() override final;
205
206
214 void resetTo (pointer p);
215
216
223 iterator begin();
224
225
233
234
238 iterator end();
239
240
245
246
247private:
251 void refill();
252
253
258 void clearBlock();
259
260
263
266};
267
268
269} // namespace SG
270
271
272#include "AthAllocators/ArenaPoolAllocator.icc"
273
274
275#endif // not ATHALLOCATORS_ARENAPOOLALLOCATOR_H
Common functionality for block-oriented allocators.
char * pointer
Type for pointers to elements.
const Params & params() const
Return this Allocator's parameters.
ArenaBlockAllocatorBase(const Params &params)
Constructor.
A large memory block that gets carved into smaller uniform elements.
Definition ArenaBlock.h:43
const_iterator(const iterator &it)
Constructor from iterator.
const_iterator(pointer p, const ArenaBlock *block)
Constructor.
const_iterator()
Default constructor.
const ArenaBlock * m_block
Block containing the current element.
void increment()
Move the iterator forward.
Non-const iterator for the pool.
iterator(pointer p, ArenaBlock *block)
Constructor.
void increment()
Move the iterator forward.
ArenaBlock * m_block
Block containing the current element.
iterator()
Default constructor.
pointer allocate()
Allocate a new element.
pointer m_end
One past the last available element in the current block, of null.
iterator begin()
Starting pool iterator.
virtual void reset() override
Free all allocated elements.
void resetTo(pointer p)
Reset pool back to a previous state.
void refill()
Add more free elements to the pool.
void clearBlock()
Reset all elements in the topmost block, and move the block to the free list.
virtual ~ArenaPoolAllocator()
Destructor.
ArenaPoolAllocator & operator=(const ArenaPoolAllocator &)=delete
pointer m_ptr
Pointer to the next free element to allocate, or null.
ArenaPoolAllocator(const Params &params)
Constructor.
void swap(ArenaPoolAllocator &other)
Swap.
virtual void erase() override final
Free all allocated elements and release memory back to the system.
iterator end()
Ending pool iterator.
ArenaPoolAllocator(const ArenaPoolAllocator &)=delete
Don't allow copy construction or assignment.
Forward declaration.
#define private