ATLAS Offline Software
|
Heap-based allocator. More...
#include <ArenaHeapAllocator.h>
Classes | |
struct | initParams |
Helper to initialize a parameters structure. More... | |
Public Types | |
typedef void | iterator |
typedef void | const_iterator |
typedef char * | pointer |
Type for pointers to elements. More... | |
typedef const char * | const_pointer |
And a const version of the pointer. More... | |
typedef void | func_t(pointer) |
Type of functions for constructor , etc. More... | |
Public Member Functions | |
ArenaHeapAllocator (const Params ¶ms) | |
Constructor. More... | |
virtual | ~ArenaHeapAllocator () |
Destructor. More... | |
ArenaHeapAllocator (const ArenaHeapAllocator &)=delete | |
Don't allow copy construction or assignment. More... | |
ArenaHeapAllocator & | operator= (const ArenaHeapAllocator &)=delete |
ArenaHeapAllocator (ArenaHeapAllocator &&other) | |
Move constructor. More... | |
ArenaHeapAllocator & | operator= (ArenaHeapAllocator &&other) |
Move assignment. More... | |
void | swap (ArenaHeapAllocator &other) |
Swap. More... | |
pointer | allocate () |
Allocate a new element. More... | |
void | free (pointer p) |
Free an element. More... | |
virtual void | reset () override |
Free all allocated elements. More... | |
virtual void | erase () override final |
Free all allocated elements and release memory back to the system. More... | |
void | swap (ArenaBlockAllocatorBase &other) |
Swap. More... | |
virtual void | reserve (size_t size) override |
Set the total number of elements cached by the allocator. More... | |
virtual Stats | stats () const override |
Return the statistics block for this allocator. More... | |
virtual const std::string & | name () const override |
Return the name of this allocator. More... | |
const Params & | params () const |
Return this Allocator's parameters. More... | |
void | protect () |
Write-protect the memory managed by this allocator. More... | |
void | unprotect () |
Write-enable the memory managed by this allocator. More... | |
virtual void | report (std::ostream &os) const |
Generate a report on the memory usage of this allocator. More... | |
Static Public Member Functions | |
template<class T > | |
static func_t * | makeConstructor (const std::false_type &) |
Make a constructor function pointer for a non-trivial constructor. More... | |
template<class T > | |
static func_t * | makeConstructor (const std::true_type &) |
Make a constructor function pointer for a trivial constructor. More... | |
template<class T > | |
static func_t * | makeDestructor (const std::false_type &) |
Make a constructor function pointer for a non-trivial destructor. More... | |
template<class T > | |
static func_t * | makeDestructor (const std::true_type &) |
Make a constructor function pointer for a trivial destructor. More... | |
template<class T > | |
static func_t * | makeClear (const std::false_type &) |
Make a function pointer for a clear function. More... | |
template<class T > | |
static func_t * | makeClear (const std::true_type &) |
Make a dummy clear function pointer. More... | |
Protected Member Functions | |
ArenaBlock * | getBlock () |
Return an empty block, either newly-allocated or from the free list. More... | |
Protected Attributes | |
Params | m_params |
The parameters for this allocator. More... | |
ArenaBlock * | m_blocks |
The list of blocks currently in use. More... | |
ArenaBlock * | m_freeblocks |
The list of free blocks. More... | |
ArenaAllocatorBase::Stats | m_stats |
The statistics structure. More... | |
bool | m_protected |
Flag whether the arena has been protected. More... | |
Private Member Functions | |
void | slowClear () |
Call clear() for all allocated elements. More... | |
pointer | refill () |
Add more free elements to the pool, and allocate a new element. More... | |
pointer & | link (pointer p) const |
Return a reference to the link for an element. More... | |
Static Private Member Functions | |
template<typename T > | |
static void | construct_fcn (pointer p) |
Call T's default constructor on the object at p . More... | |
template<typename T > | |
static void | destroy_fcn (pointer p) |
Call T's destructor on the object at p . More... | |
template<typename T > | |
static void | clear_fcn (pointer p) |
Call T::clear on the object at p . More... | |
Private Attributes | |
pointer | m_freeptr |
Pointer to the next free element. More... | |
Heap-based allocator.
See Arena.h for an overview of the arena-based memory allocators.
This is a block-based memory allocator, with heap-like behavior. This allows freeing individual elements, but we don't implement resetTo
or an iterator.
There are some extra costs though.
We need an additional pointer (‘link’) for each free element.
By default, this is done by increasing the element size by a pointer, since we don't know whether there is data in the element itself that must be preserved across free/allocate. However, if you know that part of the element may be safely while it is free, then the allocator can be configured to use that as the link instead.
When reset()
is called, we need to call clear()
on all allocated elements (if it is defined). If canReclear
is set, then we just call clear()
on all elements in allocated blocks on reset()
, regardless of whether or not the individual elements are allocated or not. Otherwise, we make two passes over the elements, first to build a list of those that are allocated and second to actually call clear()
.
An intermediate strategy, not currently implemented, could be used if the link does not overlap the element: set the link to a magic value when an element is allocated.
Definition at line 62 of file ArenaHeapAllocator.h.
typedef void SG::ArenaHeapAllocator::const_iterator |
Definition at line 190 of file ArenaHeapAllocator.h.
|
inherited |
And a const version of the pointer.
Definition at line 140 of file ArenaAllocatorBase.h.
|
inherited |
Type of functions for constructor
, etc.
Definition at line 143 of file ArenaAllocatorBase.h.
typedef void SG::ArenaHeapAllocator::iterator |
Definition at line 189 of file ArenaHeapAllocator.h.
|
inherited |
Type for pointers to elements.
Definition at line 137 of file ArenaAllocatorBase.h.
Constructor.
params | The parameters structure for this allocator. See ArenaAllocatorBase.h for the contents. |
Definition at line 27 of file ArenaHeapAllocator.cxx.
|
virtual |
Destructor.
This will free all the Allocator's storage.
Definition at line 39 of file ArenaHeapAllocator.cxx.
|
delete |
Don't allow copy construction or assignment.
SG::ArenaHeapAllocator::ArenaHeapAllocator | ( | ArenaHeapAllocator && | other | ) |
pointer SG::ArenaHeapAllocator::allocate | ( | ) |
Allocate a new element.
The fast path of this will be completely inlined.
|
staticprivateinherited |
Call T::clear
on the object at p
.
p | The object on which to run the clear . |
|
staticprivateinherited |
Call T's
default constructor on the object at p
.
p | The object on which to run the constructor. |
|
staticprivateinherited |
Call T's
destructor on the object at p
.
p | The object on which to run the destructor. |
|
finaloverridevirtual |
Free all allocated elements and release memory back to the system.
All elements allocated are freed, and all allocated blocks of memory are released back to the system. destructor
should be called on them if it was provided (preceded by clear
if provided and mustClear
was set).
Reimplemented from SG::ArenaBlockAllocatorBase.
Definition at line 129 of file ArenaHeapAllocator.cxx.
void SG::ArenaHeapAllocator::free | ( | pointer | p | ) |
Free an element.
p | The element to be freed. |
clear()
will be called on the element at this point, if it has been defined.
|
protectedinherited |
Return an empty block, either newly-allocated or from the free list.
Update statistics appropriately.
Definition at line 234 of file ArenaBlockAllocatorBase.cxx.
Return a reference to the link for an element.
p | The element. |
|
staticinherited |
Make a function pointer for a clear
function.
|
staticinherited |
Make a dummy clear
function pointer.
|
staticinherited |
Make a constructor function pointer for a non-trivial constructor.
|
staticinherited |
Make a constructor function pointer for a trivial constructor.
|
staticinherited |
Make a constructor function pointer for a non-trivial destructor.
|
staticinherited |
Make a constructor function pointer for a trivial destructor.
|
overridevirtualinherited |
Return the name of this allocator.
Implements SG::ArenaAllocatorBase.
Definition at line 214 of file ArenaBlockAllocatorBase.cxx.
ArenaHeapAllocator & SG::ArenaHeapAllocator::operator= | ( | ArenaHeapAllocator && | other | ) |
Move assignment.
Definition at line 63 of file ArenaHeapAllocator.cxx.
|
delete |
|
inherited |
Return this Allocator's parameters.
Return this allocator's parameters.
Definition at line 224 of file ArenaBlockAllocatorBase.cxx.
|
inherited |
Write-protect the memory managed by this allocator.
Adjust protection on the memory managed by this allocator to disallow writes.
Definition at line 270 of file ArenaBlockAllocatorBase.cxx.
|
private |
Add more free elements to the pool, and allocate a new element.
Definition at line 139 of file ArenaHeapAllocator.cxx.
|
virtualinherited |
Generate a report on the memory usage of this allocator.
os | Stream to which the report should be written. |
Definition at line 130 of file ArenaAllocatorBase.cxx.
|
overridevirtualinherited |
Set the total number of elements cached by the allocator.
size | The desired pool size. |
This allows changing the number of elements that are currently free but cached. Any allocated elements are not affected by this call.
If size
is greater than the total number of elements currently cached, then more will be allocated. This will preferably done with a single block, but that is not guaranteed; in addition, the allocator may allocate more elements than is requested.
If size
is smaller than the total number of elements currently cached, as many blocks as possible will be released back to the system. It may not be possible to release the number of elements requested; this should be implemented on a best-effort basis.
Implements SG::ArenaAllocatorBase.
Definition at line 120 of file ArenaBlockAllocatorBase.cxx.
|
overridevirtual |
Free all allocated elements.
All elements allocated are returned to the free state. clear
should be called on them if it was provided. The elements may continue to be cached internally, without returning to the system.
Implements SG::ArenaAllocatorBase.
Definition at line 95 of file ArenaHeapAllocator.cxx.
|
private |
|
overridevirtualinherited |
Return the statistics block for this allocator.
Implements SG::ArenaAllocatorBase.
Definition at line 196 of file ArenaBlockAllocatorBase.cxx.
|
inherited |
Swap.
Definition at line 91 of file ArenaBlockAllocatorBase.cxx.
void SG::ArenaHeapAllocator::swap | ( | ArenaHeapAllocator & | other | ) |
Swap.
Definition at line 78 of file ArenaHeapAllocator.cxx.
|
inherited |
Write-enable the memory managed by this allocator.
Adjust protection on the memory managed by this allocator to allow writes.
Definition at line 283 of file ArenaBlockAllocatorBase.cxx.
|
protectedinherited |
The list of blocks currently in use.
Definition at line 153 of file ArenaBlockAllocatorBase.h.
|
protectedinherited |
The list of free blocks.
Definition at line 156 of file ArenaBlockAllocatorBase.h.
|
private |
Pointer to the next free element.
Definition at line 213 of file ArenaHeapAllocator.h.
|
protectedinherited |
The parameters for this allocator.
Definition at line 150 of file ArenaBlockAllocatorBase.h.
|
protectedinherited |
Flag whether the arena has been protected.
Definition at line 162 of file ArenaBlockAllocatorBase.h.
|
protectedinherited |
The statistics structure.
Definition at line 159 of file ArenaBlockAllocatorBase.h.