28ArenaHeapAllocator::ArenaHeapAllocator (
const Params& params)
33 assert (params.linkOffset + sizeof (pointer) <= params.eltSize);
40ArenaHeapAllocator::~ArenaHeapAllocator()
58ArenaHeapAllocator::ArenaHeapAllocator
65 other.m_freeptr =
nullptr;
73ArenaHeapAllocator::operator=
74 (ArenaHeapAllocator&& other)
77 ArenaBlockAllocatorBase::operator= (std::move (other));
78 m_freeptr = other.m_freeptr;
79 other.m_freeptr =
nullptr;
88void ArenaHeapAllocator::swap (ArenaHeapAllocator& other)
91 ArenaBlockAllocatorBase::swap (other);
105void ArenaHeapAllocator::reset()
107 if (!m_blocks)
return;
108 if (m_params.clear) {
109 if (m_params.canReclear || m_freeptr ==
nullptr) {
111 ArenaBlock::applyList (m_blocks, m_params.clear, m_blocks->size());
120 ArenaBlock::appendList (&m_freeblocks, m_blocks);
125 m_stats.elts.inuse = 0;
126 m_stats.blocks.free += m_stats.blocks.inuse;
127 m_stats.blocks.inuse = 0;
139void ArenaHeapAllocator::erase()
141 ArenaBlockAllocatorBase::erase();
149ArenaHeapAllocator::pointer ArenaHeapAllocator::refill()
152 ArenaBlock* newblock = getBlock();
155 pointer lastelt =
nullptr;
156 size_t sz = newblock->size();
157 size_t elt_size = newblock->eltSize();
158 for (
size_t i=1;
i <
sz;
i++) {
159 pointer elt = newblock->index (i, elt_size);
167 return newblock->index (0, elt_size);
174void ArenaHeapAllocator::slowClear()
177 std::vector<pointer> free_ptrs;
178 free_ptrs.reserve (m_stats.elts.total - m_stats.elts.inuse);
180 free_ptrs.push_back (p);
182 std::sort (free_ptrs.begin(), free_ptrs.end());
185 std::vector<ArenaBlock*> blocks;
186 for (
ArenaBlock* p = m_blocks; p; p = p->link()) {
187 blocks.push_back (p);
189 std::sort (blocks.begin(), blocks.end());
194 std::vector<pointer>::iterator
pi = free_ptrs.begin();
195 std::vector<pointer>::iterator pi_end = free_ptrs.end();
196 std::vector<ArenaBlock*>::iterator bi = blocks.begin();
197 std::vector<ArenaBlock*>::iterator bi_end = blocks.end();
198 func_t*
clear = m_params.clear;
199 for (; bi != bi_end; ++bi) {
202 size_t elt_size = bl.
eltSize();
203 for (
size_t i = 0; i <
sz; i++) {
204 pointer ptr = bl.
index (i, elt_size);
205 if (
pi != pi_end && ptr == *
pi) {
A large memory block that gets carved into smaller uniform elements. See Arena.h for an overview of t...
Heap-based allocator. See Arena.h for an overview of the arena-based memory allocators.
Exceptions that can be thrown from AthAllocators.
void clear()
Empty the pool.
Common functionality for block-oriented allocators.
void eraseUnprotected()
Free all allocated elements and release memory back to the system.
A large memory block that gets carved into smaller uniform elements.
pointer index(size_t i)
Return a pointer to element i in the block.
size_t eltSize() const
Return the size of the elements in the block.
size_t size() const
Return the number of elements in the block.
Exception — Attempt to change memory protection failed.
pointer m_freeptr
Pointer to the next free element.
void slowClear()
Call clear() for all allocated elements.
pointer & link(pointer p) const
Return a reference to the link for an element.
ArenaHeapAllocator(const Params ¶ms)
Constructor.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)