ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Private Member Functions | List of all members
SG::ArenaBlockAllocatorBase Class Referenceabstract

Common functionality for block-oriented allocators. More...

#include <ArenaBlockAllocatorBase.h>

Inheritance diagram for SG::ArenaBlockAllocatorBase:
Collaboration diagram for SG::ArenaBlockAllocatorBase:

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

 ArenaBlockAllocatorBase (const Params &params)
 Constructor. More...
 
virtual ~ArenaBlockAllocatorBase ()
 Destructor. More...
 
 ArenaBlockAllocatorBase (const ArenaBlockAllocatorBase &)=delete
 Don't allow copy construction or assignment. More...
 
ArenaBlockAllocatorBaseoperator= (const ArenaBlockAllocatorBase &)=delete
 
 ArenaBlockAllocatorBase (ArenaBlockAllocatorBase &&other)
 Move constructor. More...
 
ArenaBlockAllocatorBaseoperator= (ArenaBlockAllocatorBase &&other)
 Move assignment. 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 void erase () override
 Free all allocated elements and release memory back to the system. 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 Paramsparams () 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 reset ()=0
 Free all allocated elements. 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...
 

Protected Member Functions

ArenaBlockgetBlock ()
 Return an empty block, either newly-allocated or from the free list. More...
 

Protected Attributes

Params m_params
 The parameters for this allocator. More...
 
ArenaBlockm_blocks
 The list of blocks currently in use. More...
 
ArenaBlockm_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...
 

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 functionality for block-oriented allocators.

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

This class factors out some common functionality for allocators that use ArenaBlock.

Definition at line 33 of file ArenaBlockAllocatorBase.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)
inherited

Type of functions for constructor, etc.

Definition at line 143 of file ArenaAllocatorBase.h.

◆ pointer

typedef char* SG::ArenaAllocatorBase::pointer
inherited

Type for pointers to elements.

Definition at line 137 of file ArenaAllocatorBase.h.

Constructor & Destructor Documentation

◆ ArenaBlockAllocatorBase() [1/3]

SG::ArenaBlockAllocatorBase::ArenaBlockAllocatorBase ( const Params params)

Constructor.

Parameters
paramsThe parameters structure for this allocator. See ArenaAllocatorBase.h for the contents.

Definition at line 25 of file ArenaBlockAllocatorBase.cxx.

26  : m_params (params),
27  m_blocks (nullptr),
28  m_freeblocks (nullptr),
29  m_stats(),
30  m_protected (false)
31 {
32 }

◆ ~ArenaBlockAllocatorBase()

SG::ArenaBlockAllocatorBase::~ArenaBlockAllocatorBase ( )
virtual

Destructor.

Definition at line 38 of file ArenaBlockAllocatorBase.cxx.

39 {
40  // Should be called by the derived class dtor.
41  // Can't do it from here since it may call reset(), which is
42  // pure virtual in this class.
43  //erase();
44 }

◆ ArenaBlockAllocatorBase() [2/3]

SG::ArenaBlockAllocatorBase::ArenaBlockAllocatorBase ( const ArenaBlockAllocatorBase )
delete

Don't allow copy construction or assignment.

◆ ArenaBlockAllocatorBase() [3/3]

SG::ArenaBlockAllocatorBase::ArenaBlockAllocatorBase ( ArenaBlockAllocatorBase &&  other)

Move constructor.

Definition at line 50 of file ArenaBlockAllocatorBase.cxx.

52  : m_params (other.m_params),
53  m_blocks (other.m_blocks),
54  m_freeblocks (other.m_freeblocks),
55  m_stats (other.m_stats),
56  m_protected (other.m_protected)
57 {
58  other.m_blocks = nullptr;
59  other.m_freeblocks = nullptr;
60  other.m_stats.clear();
61  other.m_protected = false;
62 }

Member Function Documentation

◆ clear_fcn()

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

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

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

Call T's destructor on the object at p.

Parameters
pThe object on which to run the destructor.

◆ erase()

void SG::ArenaBlockAllocatorBase::erase ( )
overridevirtual

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

Implements SG::ArenaAllocatorBase.

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

Definition at line 172 of file ArenaBlockAllocatorBase.cxx.

173 {
174  if (m_protected) {
175  throw SG::ExcProtected();
176  }
177  // Do we need to run clear() on the allocated elements?
178  // If so, do so via reset().
179  if (m_params.mustClear && m_params.clear) {
180  reset();
181  }
182 
183  // Kill the block lists (both free and in use).
186  m_blocks = m_freeblocks = nullptr;
187 
188  // Reset statistics.
189  m_stats.clear();
190 }

◆ getBlock()

ArenaBlock * SG::ArenaBlockAllocatorBase::getBlock ( )
protected

Return an empty block, either newly-allocated or from the free list.

Update statistics appropriately.

Definition at line 234 of file ArenaBlockAllocatorBase.cxx.

235 {
236  if (m_protected) {
237  throw SG::ExcProtected();
238  }
239 
240  ArenaBlock* newblock = m_freeblocks;
241  if (newblock) {
242  // There's something on the free list. Remove it and update statistics.
243  m_freeblocks = newblock->link();
244  --m_stats.blocks.free;
245  }
246  else {
247  // Otherwise, we need to make a new block.
250  m_stats.elts.total += newblock->size();
251  ++m_stats.blocks.total;
252  }
253  // Finish updating statistics.
254  // (Remaining ones are computed in stats().)
255  ++m_stats.blocks.inuse;
256 
257  // Link it into the in-use list and return.
258  newblock->link() = m_blocks;
259  m_blocks = newblock;
260  return newblock;
261 }

◆ makeClear() [1/2]

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

Make a function pointer for a clear function.

◆ makeClear() [2/2]

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

Make a dummy clear function pointer.

◆ makeConstructor() [1/2]

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

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 &  )
staticinherited

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 &  )
staticinherited

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 &  )
staticinherited

Make a constructor function pointer for a trivial destructor.

◆ name()

const std::string & SG::ArenaBlockAllocatorBase::name ( ) const
overridevirtual

Return the name of this allocator.

Implements SG::ArenaAllocatorBase.

Definition at line 214 of file ArenaBlockAllocatorBase.cxx.

215 {
216  return m_params.name;
217 }

◆ operator=() [1/2]

ArenaBlockAllocatorBase & SG::ArenaBlockAllocatorBase::operator= ( ArenaBlockAllocatorBase &&  other)

Move assignment.

Definition at line 69 of file ArenaBlockAllocatorBase.cxx.

71 {
72  if (this != &other) {
73  erase();
74  m_params = other.m_params;
75  m_blocks = other.m_blocks;
76  m_freeblocks = other.m_freeblocks;
77  m_stats = other.m_stats;
78  m_protected = other.m_protected;
79  other.m_blocks = nullptr;
80  other.m_freeblocks = nullptr;
81  other.m_stats.clear();
82  other.m_protected = false;
83  }
84  return *this;
85 }

◆ operator=() [2/2]

ArenaBlockAllocatorBase& SG::ArenaBlockAllocatorBase::operator= ( const ArenaBlockAllocatorBase )
delete

◆ params()

const ArenaAllocatorBase::Params & SG::ArenaBlockAllocatorBase::params ( ) const

Return this Allocator's parameters.

Return this allocator's parameters.

Definition at line 224 of file ArenaBlockAllocatorBase.cxx.

225 {
226  return m_params;
227 }

◆ protect()

void SG::ArenaBlockAllocatorBase::protect ( )

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.

271 {
273  m_protected = true;
274 }

◆ report()

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

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

void SG::ArenaBlockAllocatorBase::reserve ( size_t  size)
overridevirtual

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.

Implements SG::ArenaAllocatorBase.

Definition at line 120 of file ArenaBlockAllocatorBase.cxx.

121 {
122  if (m_protected) {
123  throw SG::ExcProtected();
124  }
125  if (size > m_stats.elts.total) {
126  // Growing the pool.
127  // Make a new block of the required size.
128  size_t sz = size - m_stats.elts.total;
129  ArenaBlock* newblock = ArenaBlock::newBlock (sz, m_params.eltSize,
131 
132  // Update statistics (others are derived in stats()).
133  ++m_stats.blocks.free;
134  ++m_stats.blocks.total;
135  m_stats.elts.total += newblock->size();
136 
137  // Add to the free list.
138  newblock->link() = m_freeblocks;
139  m_freeblocks = newblock;
140  }
141  else {
142  // Shrinking the pool.
143  // Loop while we can get rid of the first free block.
144  while (size < m_stats.elts.total &&
145  m_freeblocks &&
147  {
148  // Remove it from the free list.
149  ArenaBlock* p = m_freeblocks;
151 
152  // Update statistics (others are derived in stats()).
153  m_stats.elts.total -= p->size();
154  --m_stats.blocks.free;
155  --m_stats.blocks.total;
156 
157  // Free the block.
159  }
160  }
161 }

◆ reset()

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

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

ArenaAllocatorBase::Stats SG::ArenaBlockAllocatorBase::stats ( ) const
overridevirtual

Return the statistics block for this allocator.

Implements SG::ArenaAllocatorBase.

Definition at line 196 of file ArenaBlockAllocatorBase.cxx.

197 {
198  // Calculate derived statistics.
199  Stats stats = m_stats;
207  return stats;
208 }

◆ swap()

void SG::ArenaBlockAllocatorBase::swap ( ArenaBlockAllocatorBase other)

Swap.

Definition at line 91 of file ArenaBlockAllocatorBase.cxx.

92 {
93  if (this != &other) {
94  std::swap (m_params, other.m_params);
95  std::swap (m_blocks, other.m_blocks);
96  std::swap (m_freeblocks, other.m_freeblocks);
97  std::swap (m_stats, other.m_stats);
98  std::swap (m_protected, other.m_protected);
99  }
100 }

◆ unprotect()

void SG::ArenaBlockAllocatorBase::unprotect ( )

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.

284 {
285  if (m_protected) {
287  m_protected = false;
288  }
289 }

Member Data Documentation

◆ m_blocks

ArenaBlock* SG::ArenaBlockAllocatorBase::m_blocks
protected

The list of blocks currently in use.

Definition at line 153 of file ArenaBlockAllocatorBase.h.

◆ m_freeblocks

ArenaBlock* SG::ArenaBlockAllocatorBase::m_freeblocks
protected

The list of free blocks.

Definition at line 156 of file ArenaBlockAllocatorBase.h.

◆ m_params

Params SG::ArenaBlockAllocatorBase::m_params
protected

The parameters for this allocator.

Definition at line 150 of file ArenaBlockAllocatorBase.h.

◆ m_protected

bool SG::ArenaBlockAllocatorBase::m_protected
protected

Flag whether the arena has been protected.

Definition at line 162 of file ArenaBlockAllocatorBase.h.

◆ m_stats

ArenaAllocatorBase::Stats SG::ArenaBlockAllocatorBase::m_stats
protected

The statistics structure.

Definition at line 159 of file ArenaBlockAllocatorBase.h.


The documentation for this class was generated from the following files:
SG::ArenaBlockAllocatorBase::params
const Params & params() const
Return this Allocator's parameters.
Definition: ArenaBlockAllocatorBase.cxx:224
SG::ArenaBlockAllocatorBase::m_blocks
ArenaBlock * m_blocks
The list of blocks currently in use.
Definition: ArenaBlockAllocatorBase.h:153
SG::ArenaAllocatorBase::Params::constructor
func_t * constructor
Constructor function for elements.
Definition: ArenaAllocatorBase.h:170
SG::ArenaAllocatorBase::stats
virtual Stats stats() const =0
Return the statistics block for this allocator.
fitman.sz
sz
Definition: fitman.py:527
SG::ArenaBlock::destroy
static void destroy(ArenaBlock *p, func_t *dtor)
Destroy a block.
Definition: ArenaBlock.cxx:69
SG::ArenaAllocatorBase::Params::nblock
size_t nblock
The number of elements we should allocate in a single block (hint only).
Definition: ArenaAllocatorBase.h:162
SG::ArenaAllocatorBase::Params::mustClear
bool mustClear
If true, the clear call cannot be skipped before destructor.
Definition: ArenaAllocatorBase.h:181
SG::ArenaBlockAllocatorBase::m_params
Params m_params
The parameters for this allocator.
Definition: ArenaBlockAllocatorBase.h:150
SG::ArenaBlock::overhead
static size_t overhead()
Return the per-block memory overhead, in bytes.
Definition: ArenaBlock.cxx:157
SG::ArenaBlock::newBlock
static ArenaBlock * newBlock(size_t n, size_t elt_size, func_t *ctor)
Create a new block.
Definition: ArenaBlock.cxx:41
SG::ArenaBlockAllocatorBase::erase
virtual void erase() override
Free all allocated elements and release memory back to the system.
Definition: ArenaBlockAllocatorBase.cxx:172
SG::ArenaAllocatorBase::Stats::Stat::free
size_t free
Number of items currently not allocated by the application but cached by the allocator.
Definition: ArenaAllocatorBase.h:205
SG::ArenaAllocatorBase::Params::clear
func_t * clear
Clear function for elements.
Definition: ArenaAllocatorBase.h:175
SG::ArenaBlockAllocatorBase::m_protected
bool m_protected
Flag whether the arena has been protected.
Definition: ArenaBlockAllocatorBase.h:162
SG::ArenaAllocatorBase::Stats::Stat::inuse
size_t inuse
Number of items currently allocated by the application.
Definition: ArenaAllocatorBase.h:202
SG::ArenaAllocatorBase::Stats::blocks
Stat blocks
Counts of blocks.
Definition: ArenaAllocatorBase.h:217
SG::ArenaBlock::unprotectList
static void unprotectList(ArenaBlock *p)
Write-enable all blocks in a list.
Definition: ArenaBlock.cxx:218
SG::ArenaBlock::link
ArenaBlock *& link()
Return the link pointer of the block.
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SG::ArenaAllocatorBase::Stats::clear
void clear()
Reset to zero.
Definition: ArenaAllocatorBase.cxx:78
SG::ArenaBlockAllocatorBase::stats
virtual Stats stats() const override
Return the statistics block for this allocator.
Definition: ArenaBlockAllocatorBase.cxx:196
SG::ArenaBlock::size
size_t size() const
Return the number of elements in the block.
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
SG::ArenaAllocatorBase::Params::name
std::string name
The name of this allocator.
Definition: ArenaAllocatorBase.h:152
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
SG::ExcProtected
Exception — Attempt to change protected arena.
Definition: Control/AthAllocators/AthAllocators/exceptions.h:58
SG::ArenaAllocatorBase::Stats::bytes
Stat bytes
Counts of bytes.
Definition: ArenaAllocatorBase.h:221
SG::ArenaAllocatorBase::Stats::Stat::total
size_t total
Total number of items held by the allocator.
Definition: ArenaAllocatorBase.h:207
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
SG::ArenaBlockAllocatorBase::m_stats
ArenaAllocatorBase::Stats m_stats
The statistics structure.
Definition: ArenaBlockAllocatorBase.h:159
SG::ArenaBlock::protectList
static void protectList(ArenaBlock *p)
Write-protect all blocks in a list.
Definition: ArenaBlock.cxx:203
SG::ArenaBlock::destroyList
static void destroyList(ArenaBlock *p, func_t *dtor)
Destroy all blocks in a list.
Definition: ArenaBlock.cxx:91
SG::ArenaBlockAllocatorBase::m_freeblocks
ArenaBlock * m_freeblocks
The list of free blocks.
Definition: ArenaBlockAllocatorBase.h:156
SG::ArenaAllocatorBase::Params::eltSize
size_t eltSize
The size in bytes of the individual elements we're allocating.
Definition: ArenaAllocatorBase.h:155
SG::ArenaAllocatorBase::reset
virtual void reset()=0
Free all allocated elements.
SG::ArenaAllocatorBase::Params::destructor
func_t * destructor
Destructor function for elements.
Definition: ArenaAllocatorBase.h:172
SG::ArenaAllocatorBase::Stats::elts
Stat elts
Counts of elements.
Definition: ArenaAllocatorBase.h:219
SG::ArenaAllocatorBase::name
virtual const std::string & name() const =0
Return the name of this allocator.