ATLAS Offline Software
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
SG::ArenaHandleBase Class Reference

Base class for all Handle classes, containing parts that do not depend on the referenced type. More...

#include <ArenaHandleBase.h>

Inheritance diagram for SG::ArenaHandleBase:
Collaboration diagram for SG::ArenaHandleBase:

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

ArenaAllocatorBasebaseAllocator ()
 Return the current Allocator which we are referencing. More...
 
const ArenaAllocatorBasebaseAllocator () const
 Return the current Allocator which we are referencing. More...
 

Private Attributes

LockedAllocator m_allocator
 The associated allocator object. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ArenaHandleBase() [1/3]

SG::ArenaHandleBase::ArenaHandleBase ( ArenaHeader header,
size_t  index 
)

Constructor.

Parameters
headerThe group of Arenas which this Handle may reference. May be null to select the global default.
indexThe index of this Handle's Allocator type.

Definition at line 28 of file ArenaHandleBase.cxx.

30  allocator (index))
31 {
32 }

◆ ArenaHandleBase() [2/3]

SG::ArenaHandleBase::ArenaHandleBase ( ArenaHeader header,
const EventContext &  ctx,
size_t  index 
)

Constructor.

Parameters
headerThe group of Arenas which this Handle may reference. May be null to select the global default.
ctxEvent context to select the Arena for the proper event slot.
indexThe index of this Handle's Allocator type.

Definition at line 42 of file ArenaHandleBase.cxx.

46  allocator (ctx, index))
47 {
48 }

◆ ArenaHandleBase() [3/3]

SG::ArenaHandleBase::ArenaHandleBase ( ArenaBase arena,
size_t  index 
)

Constructor.

Parameters
arenaThe particular Arena to use.
indexThe index of this Handle's Allocator type.

Definition at line 56 of file ArenaHandleBase.cxx.

57  : m_allocator (arena->allocator (index))
58 {
59 }

Member Function Documentation

◆ baseAllocator() [1/2]

ArenaAllocatorBase* SG::ArenaHandleBase::baseAllocator ( )
protected

Return the current Allocator which we are referencing.

This may cause a new Allocator to be created.

◆ baseAllocator() [2/2]

const ArenaAllocatorBase* SG::ArenaHandleBase::baseAllocator ( ) const
protected

Return the current Allocator which we are referencing.

This may cause a new Allocator to be created.

◆ erase()

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.

88 {
89  return baseAllocator()->erase();
90 }

◆ reserve()

void SG::ArenaHandleBase::reserve ( size_t  size)

Set the total number of elements cached by the allocator (in the current Arena).

Parameters
sizeThe 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.

112 {
113  return baseAllocator()->reserve (size);
114 }

◆ reset()

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.

72 {
73  return baseAllocator()->reset();
74 }

◆ stats()

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.

122 {
123  return baseAllocator()->stats();
124 }

Member Data Documentation

◆ m_allocator

LockedAllocator SG::ArenaHandleBase::m_allocator
private

The associated allocator object.

Definition at line 160 of file ArenaHandleBase.h.


The documentation for this class was generated from the following files:
SG::ArenaHandleBase::baseAllocator
ArenaAllocatorBase * baseAllocator()
Return the current Allocator which we are referencing.
SG::ArenaAllocatorBase::stats
virtual Stats stats() const =0
Return the statistics block for this allocator.
header
Definition: hcg.cxx:526
index
Definition: index.py:1
SG::ArenaAllocatorBase::reserve
virtual void reserve(size_t size)=0
Set the total number of elements cached by the allocator.
SG::ArenaAllocatorBase::erase
virtual void erase()=0
Free all allocated elements and release memory back to the system.
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
SG::ArenaHeader::defaultHeader
static ArenaHeader * defaultHeader()
Return the global default Header instance.
Definition: ArenaHeader.cxx:164
SG::ArenaAllocatorBase::reset
virtual void reset()=0
Free all allocated elements.
SG::ArenaHandleBase::m_allocator
LockedAllocator m_allocator
The associated allocator object.
Definition: ArenaHandleBase.h:160