ATLAS Offline Software
|
Base class for all Handle
classes, containing parts that do not depend on the referenced type.
More...
#include <ArenaHandleBase.h>
Public Member Functions | |
ArenaHandleBase (ArenaHeader *header, size_t index) | |
Constructor. More... | |
ArenaHandleBase (ArenaHeader *header, const EventContext &ctx, size_t index) | |
Constructor. More... | |
ArenaHandleBase (ArenaBase *arena, size_t index) | |
Constructor. More... | |
void | reset () |
Free all allocated elements (of this type in the current Arena). More... | |
void | erase () |
Free all allocated elements and release memory back to the system (of this type in the current Arena). More... | |
void | reserve (size_t size) |
Set the total number of elements cached by the allocator (in the current Arena). More... | |
ArenaAllocatorBase::Stats | stats () const |
Return the statistics block for this allocator, for the current Arena. More... | |
Protected Member Functions | |
ArenaAllocatorBase * | baseAllocator () |
Return the current Allocator which we are referencing. More... | |
const ArenaAllocatorBase * | baseAllocator () const |
Return the current Allocator which we are referencing. More... | |
Private Attributes | |
LockedAllocator | m_allocator |
The associated allocator object. More... | |
Base class for all Handle
classes, containing parts that do not depend on the referenced type.
See Arena.h for an overview of the arena-based memory allocators.
A Handle is the interface the application uses to allocate memory. A Handle is templated on the type being allocated as well as on the underlying Allocator. When a Handle is constructed, it is associated with the Allocator associated with the Arena that is current at that time (a new Allocator is automatically created if required). Therefore, a Handle should not be passed between threads, and Handle objects should not exist across any point where the current store/Arena may be changed.
A Handle also holds a lock on its associated allocator. Therefore, if you try to create two handle instances referencing the same allocator (i.e, same type and same thread), you'll get a deadlock.
Multiple Handle implementations may be available, implementing different strategies for initializing the elements.
This class contains the parts of the Handle interface that do not depend on the template parameters.
The first time a given Handle type is seen, it is assigned an index in the the the Arena
Allocator
vector. A Handle
forwards operations to the underlying Allocator
.
Definition at line 58 of file ArenaHandleBase.h.
SG::ArenaHandleBase::ArenaHandleBase | ( | ArenaHeader * | header, |
size_t | index | ||
) |
Constructor.
header | The group of Arenas which this Handle may reference. May be null to select the global default. |
index | The index of this Handle's Allocator type. |
Definition at line 28 of file ArenaHandleBase.cxx.
SG::ArenaHandleBase::ArenaHandleBase | ( | ArenaHeader * | header, |
const EventContext & | ctx, | ||
size_t | index | ||
) |
Constructor.
header | The group of Arenas which this Handle may reference. May be null to select the global default. |
ctx | Event context to select the Arena for the proper event slot. |
index | The index of this Handle's Allocator type. |
Definition at line 42 of file ArenaHandleBase.cxx.
SG::ArenaHandleBase::ArenaHandleBase | ( | ArenaBase * | arena, |
size_t | index | ||
) |
Constructor.
arena | The particular Arena to use. |
index | The index of this Handle's Allocator type. |
Definition at line 56 of file ArenaHandleBase.cxx.
|
protected |
Return the current Allocator which we are referencing.
This may cause a new Allocator to be created.
|
protected |
Return the current Allocator which we are referencing.
This may cause a new Allocator to be created.
void SG::ArenaHandleBase::erase | ( | ) |
Free all allocated elements and release memory back to the system (of this type in the current Arena).
All elements allocated in the current Arena by our associated Allocator 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).
Definition at line 87 of file ArenaHandleBase.cxx.
void SG::ArenaHandleBase::reserve | ( | size_t | size | ) |
Set the total number of elements cached by the allocator (in the current Arena).
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.
Definition at line 111 of file ArenaHandleBase.cxx.
void SG::ArenaHandleBase::reset | ( | ) |
Free all allocated elements (of this type in the current Arena).
All elements allocated in the current Arena by our associated Allocator 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.
Definition at line 71 of file ArenaHandleBase.cxx.
ArenaAllocatorBase::Stats SG::ArenaHandleBase::stats | ( | ) | const |
Return the statistics block for this allocator, for the current Arena.
Definition at line 121 of file ArenaHandleBase.cxx.
|
private |
The associated allocator object.
Definition at line 160 of file ArenaHandleBase.h.