ATLAS Offline Software
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | List of all members
SG::ArenaAllocatorBase Class Referenceabstract

Common base class for arena allocator classes. More...

#include <ArenaAllocatorBase.h>

Inheritance diagram for SG::ArenaAllocatorBase:
Collaboration diagram for SG::ArenaAllocatorBase:

Classes

struct  initParams
 Helper to initialize a parameters structure. More...
 
struct  Params
 Allocator parameters. More...
 
struct  Stats
 Statistics for an allocator. 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

virtual ~ArenaAllocatorBase ()
 Destructor. More...
 
virtual void reset ()=0
 Free all allocated elements. More...
 
virtual void erase ()=0
 Free all allocated elements and release memory back to the system. More...
 
virtual void reserve (size_t size)=0
 Set the total number of elements cached by the allocator. More...
 
virtual Stats stats () const =0
 Return the statistics block for this allocator. More...
 
virtual const std::string & name () const =0
 Return the name of 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_tmakeConstructor (const std::false_type &)
 Make a constructor function pointer for a non-trivial constructor. More...
 
template<class T >
static func_tmakeConstructor (const std::true_type &)
 Make a constructor function pointer for a trivial constructor. More...
 
template<class T >
static func_tmakeDestructor (const std::false_type &)
 Make a constructor function pointer for a non-trivial destructor. More...
 
template<class T >
static func_tmakeDestructor (const std::true_type &)
 Make a constructor function pointer for a trivial destructor. More...
 
template<class T >
static func_tmakeClear (const std::false_type &)
 Make a function pointer for a clear function. More...
 
template<class T >
static func_tmakeClear (const std::true_type &)
 Make a dummy clear function pointer. 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...
 

Detailed Description

Common base class for arena allocator classes.

See Arena.h for an overview of the arena-based memory allocators.

This base class provides the interfaces and common behavior for arena allocator classes. An allocator class is responsible for the actual allocation and deletion of objects. It is expected that unallocated objects may be maintained in a pool for efficiency. In addition, it should be possible to free at once all the objects that this allocator has allocated. See below for the details of the interface that classes deriving from this should implement.

A matter of terminology. The objects that we allocate and free are called ‘elements’. As mentioned, it is expected that the memory will be allocated from the system for large groups of elements at any one time; these groups are called ‘blocks’.

The allocator classes do not themselves depend on the type of the object being allocated. Instead, the necessary information is included in a parameters object of class Params that is passed to the allocator on construction. These parameters include:

The allocator class should maintain statistics for the memory it has allocated. These are grouped in the Stats structure. It should report the amount of space in use, the amount of free space (allocated from the system but not allocated by the application), and the total space allocated from the system, broken down into blocks, elements, and bytes. The derived allocator class may of course extend the provided statistics.

The interface provided by derived allocator classes should consist of at least the following:

Definition at line 133 of file ArenaAllocatorBase.h.

Member Typedef Documentation

◆ const_pointer

And a const version of the pointer.

Definition at line 140 of file ArenaAllocatorBase.h.

◆ func_t

typedef void SG::ArenaAllocatorBase::func_t(pointer)

Type of functions for constructor, etc.

Definition at line 143 of file ArenaAllocatorBase.h.

◆ pointer

Type for pointers to elements.

Definition at line 137 of file ArenaAllocatorBase.h.

Constructor & Destructor Documentation

◆ ~ArenaAllocatorBase()

virtual SG::ArenaAllocatorBase::~ArenaAllocatorBase ( )
inlinevirtual

Destructor.

Definition at line 228 of file ArenaAllocatorBase.h.

228 {}

Member Function Documentation

◆ clear_fcn()

template<typename T >
static void SG::ArenaAllocatorBase::clear_fcn ( pointer  p)
staticprivate

Call T::clear on the object at p.

Parameters
pThe object on which to run the clear.

◆ construct_fcn()

template<typename T >
static void SG::ArenaAllocatorBase::construct_fcn ( pointer  p)
staticprivate

Call T's default constructor on the object at p.

Parameters
pThe object on which to run the constructor.

◆ destroy_fcn()

template<typename T >
static void SG::ArenaAllocatorBase::destroy_fcn ( pointer  p)
staticprivate

Call T's destructor on the object at p.

Parameters
pThe object on which to run the destructor.

◆ erase()

virtual void SG::ArenaAllocatorBase::erase ( )
pure virtual

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).

Implemented in SG::ArenaPoolAllocator, SG::ArenaHeapAllocator, and SG::ArenaBlockAllocatorBase.

◆ makeClear() [1/2]

template<class T >
static func_t* SG::ArenaAllocatorBase::makeClear ( const std::false_type &  )
static

Make a function pointer for a clear function.

◆ makeClear() [2/2]

template<class T >
static func_t* SG::ArenaAllocatorBase::makeClear ( const std::true_type &  )
static

Make a dummy clear function pointer.

◆ makeConstructor() [1/2]

template<class T >
static func_t* SG::ArenaAllocatorBase::makeConstructor ( const std::false_type &  )
static

Make a constructor function pointer for a non-trivial constructor.

◆ makeConstructor() [2/2]

template<class T >
static func_t* SG::ArenaAllocatorBase::makeConstructor ( const std::true_type &  )
static

Make a constructor function pointer for a trivial constructor.

◆ makeDestructor() [1/2]

template<class T >
static func_t* SG::ArenaAllocatorBase::makeDestructor ( const std::false_type &  )
static

Make a constructor function pointer for a non-trivial destructor.

◆ makeDestructor() [2/2]

template<class T >
static func_t* SG::ArenaAllocatorBase::makeDestructor ( const std::true_type &  )
static

Make a constructor function pointer for a trivial destructor.

◆ name()

virtual const std::string& SG::ArenaAllocatorBase::name ( ) const
pure virtual

Return the name of this allocator.

Implemented in SG::ArenaBlockAllocatorBase.

◆ report()

void SG::ArenaAllocatorBase::report ( std::ostream &  os) const
virtual

Generate a report on the memory usage of this allocator.

Parameters
osStream to which the report should be written.

Definition at line 131 of file ArenaAllocatorBase.cxx.

132 {
133  os << " " << stats() << " " << name() << std::endl;
134 }

◆ reserve()

virtual void SG::ArenaAllocatorBase::reserve ( size_t  size)
pure virtual

Set the total number of elements cached by the allocator.

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.

Implemented in SG::ArenaBlockAllocatorBase.

◆ reset()

virtual void SG::ArenaAllocatorBase::reset ( )
pure virtual

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.

Implemented in SG::ArenaPoolAllocator, and SG::ArenaHeapAllocator.

◆ stats()

virtual Stats SG::ArenaAllocatorBase::stats ( ) const
pure virtual

Return the statistics block for this allocator.

Implemented in SG::ArenaBlockAllocatorBase.


The documentation for this class was generated from the following files:
SG::ArenaAllocatorBase::stats
virtual Stats stats() const =0
Return the statistics block for this allocator.
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
CaloRecGPU::CUDA_Helpers::allocate
void * allocate(const size_t num)
Allocates and returns the address of num bytes from GPU memory.
SG::ArenaAllocatorBase::pointer
char * pointer
Type for pointers to elements.
Definition: ArenaAllocatorBase.h:137
SG::ArenaAllocatorBase::name
virtual const std::string & name() const =0
Return the name of this allocator.