ATLAS Offline Software
|
Pool-based allocator. More...
#include <ArenaPoolAllocator.h>
Classes | |
class | const_iterator |
Const iterator for the pool. More... | |
class | iterator |
Non-const iterator for the pool. More... | |
Public Types | |
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 | |
ArenaPoolAllocator (const Params ¶ms) | |
Constructor. More... | |
virtual | ~ArenaPoolAllocator () |
Destructor. More... | |
ArenaPoolAllocator (const ArenaPoolAllocator &)=delete | |
Don't allow copy construction or assignment. More... | |
ArenaPoolAllocator & | operator= (const ArenaPoolAllocator &)=delete |
ArenaPoolAllocator (ArenaPoolAllocator &&other) | |
Move constructor. More... | |
ArenaPoolAllocator & | operator= (ArenaPoolAllocator &&other) |
Move assignment. More... | |
void | swap (ArenaPoolAllocator &other) |
Swap. More... | |
pointer | allocate () |
Allocate a new 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 | resetTo (pointer p) |
Reset pool back to a previous state. More... | |
iterator | begin () |
Starting pool iterator. More... | |
const_iterator | begin () const |
Starting pool const iterator. More... | |
iterator | end () |
Ending pool iterator. More... | |
const_iterator | end () const |
Ending pool const iterator. 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 | refill () |
Add more free elements to the pool. More... | |
void | clearBlock () |
Reset all elements in the topmost block, and move the block to the free list. 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_ptr |
Pointer to the next free element to allocate, or null. More... | |
pointer | m_end |
One past the last available element in the current block, of null. More... | |
Pool-based allocator.
See Arena.h for an overview of the arena-based memory allocators.
This is a block-based memory allocator, with stack-like behavior (like the DataPool
class). We do not allow freeing individual elements; instead, we support resetTo(p)
, which frees and
all elements allocated after it (in this allocator). We also implement an iterator over the allocated blocks.
Definition at line 38 of file ArenaPoolAllocator.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.
|
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 96 of file ArenaPoolAllocator.cxx.
|
virtual |
Destructor.
This will free all the Allocator's storage.
Definition at line 107 of file ArenaPoolAllocator.cxx.
|
delete |
Don't allow copy construction or assignment.
SG::ArenaPoolAllocator::ArenaPoolAllocator | ( | ArenaPoolAllocator && | other | ) |
Move constructor.
Definition at line 116 of file ArenaPoolAllocator.cxx.
pointer SG::ArenaPoolAllocator::allocate | ( | ) |
Allocate a new element.
The fast path of this will be completely inlined.
ArenaPoolAllocator::iterator SG::ArenaPoolAllocator::begin | ( | ) |
Starting pool iterator.
This will iterate over all allocated elements (in unspecified order). It is a forward_iterator
.
Definition at line 261 of file ArenaPoolAllocator.cxx.
ArenaPoolAllocator::const_iterator SG::ArenaPoolAllocator::begin | ( | ) | const |
Starting pool const iterator.
This will iterate over all allocated elements (in unspecified order). It is a forward_iterator
.
Definition at line 274 of file ArenaPoolAllocator.cxx.
|
staticprivateinherited |
Call T::clear
on the object at p
.
p | The object on which to run the clear . |
|
private |
Reset all elements in the topmost block, and move the block to the free list.
Definition at line 319 of file ArenaPoolAllocator.cxx.
|
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. |
ArenaPoolAllocator::iterator SG::ArenaPoolAllocator::end | ( | ) |
Ending pool iterator.
Definition at line 284 of file ArenaPoolAllocator.cxx.
ArenaPoolAllocator::const_iterator SG::ArenaPoolAllocator::end | ( | ) | const |
Ending pool const iterator.
Definition at line 294 of file ArenaPoolAllocator.cxx.
|
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 191 of file ArenaPoolAllocator.cxx.
|
protectedinherited |
Return an empty block, either newly-allocated or from the free list.
Update statistics appropriately.
Definition at line 234 of file ArenaBlockAllocatorBase.cxx.
|
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.
ArenaPoolAllocator & SG::ArenaPoolAllocator::operator= | ( | ArenaPoolAllocator && | other | ) |
|
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.
Definition at line 304 of file ArenaPoolAllocator.cxx.
|
virtualinherited |
Generate a report on the memory usage of this allocator.
os | Stream to which the report should be written. |
Definition at line 131 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 169 of file ArenaPoolAllocator.cxx.
void SG::ArenaPoolAllocator::resetTo | ( | pointer | blk | ) |
Reset pool back to a previous state.
p | The pointer back to which to reset. |
This will free (a la reset
) the element p
and all elements that have been allocated after it from this allocator.
blk | The pointer back to which to reset. |
This will free (a la reset
) the element p
and all elements that have been allocated after it from this allocator.
Definition at line 208 of file ArenaPoolAllocator.cxx.
|
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::ArenaPoolAllocator::swap | ( | ArenaPoolAllocator & | other | ) |
|
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.
|
private |
One past the last available element in the current block, of null.
Definition at line 266 of file ArenaPoolAllocator.h.
|
protectedinherited |
The list of free blocks.
Definition at line 156 of file ArenaBlockAllocatorBase.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.
|
private |
Pointer to the next free element to allocate, or null.
Definition at line 263 of file ArenaPoolAllocator.h.
|
protectedinherited |
The statistics structure.
Definition at line 159 of file ArenaBlockAllocatorBase.h.