ATLAS Offline Software
Classes | Namespaces
Arena.h File Reference

Collection of memory allocators with a common lifetime, plus subsystem summary. More...

#include "AthAllocators/ArenaBase.h"
#include "AthAllocators/ArenaHeader.h"
#include "AthAllocators/ArenaAllocatorCreator.h"
#include "AthAllocators/ArenaAllocatorBase.h"
#include <cstdlib>
#include <string>
#include <ostream>
Include dependency graph for Arena.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  SG::Arena
 Collection of memory allocators with a common lifetime,. More...
 
class  SG::Arena::Push
 Helper class for making Arena instances current in a stack-like manner. More...
 

Namespaces

 SG
 Forward declaration.
 

Detailed Description

Collection of memory allocators with a common lifetime, plus subsystem summary.

Author
scott snyder
Date
May 2007 The Arena classes provide a framework for memory allocation. It supports the following general features:

First, a bit of terminology; this also summarizes the major components of the library. This will be followed by more detailed descriptions. See also the individual class headers.

Here are some more details about these components. For full details, see the individual class headers.

An Allocator is the fundamental allocator for a single type. Allocator instances generally request memory from the system in big blocks and then divide it up into individual elements. The memory allocated from the system is generally not returned to the system unless explicitly requested; elements not currently in use are kept in a pool for fast allocation. An Allocator class does not depend on the type being allocated. Instead, the necessary information is passed to the Allocator on creation in a parameters structure. This includes the element size, as well as three function pointers:

Any of these may be null, in which case the corresponding call is skipped.

An Allocator has a name, which is used both to identify it in the Allocator registry when Allocators are created on demand and in memory statistics reports. An Allocator must support these operations:

There are some additional operations which an Allocator may optionally implement:

Two Allocator implementations are currently available in the library:

Allocator objects are grouped into Arenas. Each Arena contains a vector of Allocator objects. Each distinct Allocator type is assigned an index into this vector; these indices are globally unique. An Arena is associated with a ArenaHeader, which maintains a notion of the ‘current’ Arena; the ArenaHeader holds a reference to the Allocator vector of the current Arena. An Arena has a makeCurrent operation to nominate it as the current Arena for its ArenaHeader. A helper class Arena::Push is provided to change the current Arena in a stack-like manner. An Arena also has operations to reset or erase all of its Allocators, as well as for summing statistics over them all. An Arena also has a name, which is used in printing statistics reports.

The object that the application uses to allocate memory is provided by the Handle classes. These are templated on the type being allocated as well as on the underlying Allocator class. A Handle is created by passing in the Arena (or ArenaHeader) with which it is created, as well as any optional creation parameters for the Allocator. The first time a given type is seen, it is assigned an index the the Arena Allocator vector. When a Handle is created, it will look up the proper Allocator instance in the current Arena, creating it if needed. The Handle will then forward operations to the underlying Allocator. The library provides two Handle implementations:

An example of the basic usage might be something like this.

class Example { ...
SG::Arena m_arena;
...};
Example::Example()
// Associates with the default ArenaHeader.
: m_arena ("myarena") { ...
...}
ret Example::execute() { ...
SG::Arena::Push push (m_arena);
MyObj* obj = handle.allocate();
...}
ret Example::newEvent() { ...
m_arena.reset();
... }

See also the unit tests for the Handle classes.

Definition in file Arena.h.

SG::ArenaCachingHandle
User interface for allocating memory that caches constructed objects.
Definition: ArenaCachingHandle.h:78
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
SG::ArenaCachingHandle::allocate
pointer allocate()
Allocate a new element.
SG::Arena
Collection of memory allocators with a common lifetime,.
Definition: Arena.h:238
python.PyAthena.obj
obj
Definition: PyAthena.py:132
SG::Arena::Push
Helper class for making Arena instances current in a stack-like manner.
Definition: Arena.h:273