ATLAS Offline Software
ArenaHeapSTLAllocator.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4 */
41 #ifndef ATLALLOCATORS_ARENAHEAPSTLALLOCATOR
42 #define ATLALLOCATORS_ARENAHEAPSTLALLOCATOR
43 
44 
46 #include "CxxUtils/concepts.h"
48 #include <string>
49 #include <cstddef>
50 
51 
52 namespace SG {
53 
54 
60 template <class T>
62  : public ArenaHeapAllocator::initParams<T, false, true, true>
63 {
64 public:
67 
75  ArenaHeapSTLAllocator_initParams (size_t nblock = 1000,
76  const std::string& name = "");
77 
80 
82  // Note: gcc 3.2.3 doesn't allow defining this out-of-line.
83  operator ArenaAllocatorBase::Params() const { return params(); }
84 };
85 
86 
93 template <class T, class VETO=T>
95 {
96 public:
98  typedef T* pointer;
99  typedef const T* const_pointer;
100  typedef T& reference;
101  typedef const T& const_reference;
102  typedef T value_type;
103  typedef size_t size_type;
104  typedef ptrdiff_t difference_type;
105 
107  typedef std::false_type propagate_on_container_copy_assignment;
108 
111  typedef std::true_type propagate_on_container_swap;
112 
113 
115  template <class U> struct rebind {
117  };
118 
119 
127  ArenaHeapSTLAllocator (size_t nblock = 1000, const std::string& name = "");
128 
129 
136 
137 
143  template <class U, class V>
145 
146 
153 
154 
161 
162 
167 
168 
176 
177 
186 
187 
196 
197 
198  // We don't bother to supply a more general constructor --- shouldn't
199  // be needed.
200 
201 
204  ATH_MEMBER_REQUIRES(!(std::is_same_v<reference,const_reference>),
206  address (const_reference x) const { return &x; }
207 
208 
214  pointer allocate (size_type n, const void* hint = 0);
215 
216 
222  ATH_MEMBER_REQUIRES(!(std::is_same_v<pointer,const_pointer>), void)
224  {
225  pointer p_nc ATLAS_THREAD_SAFE = const_cast<pointer>(p);
226  deallocate (p_nc, n);
227  }
228 
229 
235  size_type max_size() const throw();
236 
237 
243  template <class... Args>
244  void construct (pointer p, Args&&... args);
245 
246 
251  void destroy (pointer p);
252 
253 
257  size_t nblock() const;
258 
259 
263  const std::string& name() const;
264 
265 
274  void reset();
275 
276 
285  void erase();
286 
287 
305  void reserve (size_t size);
306 
307 
312 
313 
318 
319 
326  void protect();
327 
328 
335  void unprotect();
336 
337 
338 private:
341 };
342 
343 
344 
346 template <class T>
348 
349 
369 template <class T>
371  : public std::allocator<T>
372 {
373 public:
374  typedef std::allocator<T> base;
375 
377  typedef typename base::value_type value_type;
378  typedef typename base::size_type size_type;
379  typedef typename base::difference_type difference_type;
380 
381 
383  template <class U> struct rebind {
385  };
386 
387 
395  ArenaHeapSTLAllocator (size_t nblock = 1000, const std::string& name = "");
396 
397 
403  template <class U, class V>
405 
406 
407  // We don't bother to supply a more general constructor --- shouldn't
408  // be needed.
409 
410 
414  size_t nblock() const;
415 
416 
420  const std::string& name() const;
421 
422 
427 
428 
433 
434 
440  template <class CONT>
441  static
443 
444 
445 private:
447  size_t m_nblock;
448 
450  std::string m_name;
451 
454 };
455 
456 
463 template <class T>
465  : public ArenaHeapSTLAllocator<T, T>
466 {
467 public:
473  template <class U, class V>
475  ArenaBlockAllocatorBase* poolptr_nc);
476 
477 
486  void reset();
487 
488 
497  void erase();
498 
499 
517  void reserve (size_t size);
518 
519 
526  void protect();
527 
528 
535  void unprotect();
536 
537 
538 private:
541 };
542 
543 
552 template <class T, class VETO>
554 
555 
556 } // namespace SG
557 
558 
560 
561 
562 #endif // ATLALLOCATORS_ARENAHEAPSTLALLOCATOR
SG::ArenaHeapSTLAllocator::allocate
pointer allocate(size_type n, const void *hint=0)
Allocate new objects.
SG::ArenaHeapSTLAllocator_initParams::params
ArenaAllocatorBase::Params params() const
Return an initialized parameters structure.
SG::ArenaHeapSTLAllocator< T, T >::m_nblock
size_t m_nblock
Saved hinted number of objects per block.
Definition: ArenaHeapSTLAllocator.h:447
SG::ArenaHeapSTLAllocator::rebind::other
ArenaHeapSTLAllocator< U, VETO > other
Definition: ArenaHeapSTLAllocator.h:116
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::ArenaHeapSTLAllocator::operator==
bool operator==(const ArenaHeapSTLAllocator &other) const
Equality test.
SG::ArenaHeapSTLAllocator< T, T >::size_type
base::size_type size_type
Definition: ArenaHeapSTLAllocator.h:378
SG::ArenaHeapSTLAllocator::size_type
size_t size_type
Definition: ArenaHeapSTLAllocator.h:103
SG::ArenaNonConstHeapSTLAllocator::reset
void reset()
Free all allocated elements.
SG::ArenaNonConstHeapSTLAllocator::protect
void protect()
Write-protect the memory managed by this allocator.
SG::ArenaHeapSTLAllocator::propagate_on_container_move_assignment
std::true_type propagate_on_container_move_assignment
Move allocators on move/swap.
Definition: ArenaHeapSTLAllocator.h:110
SG::ArenaHeapAllocator
Heap-based allocator.
Definition: ArenaHeapAllocator.h:64
SG::ArenaHeapSTLAllocator
STL-style allocator wrapper for ArenaHeapAllocator.
Definition: ArenaHeapSTLAllocator.h:95
taskman.template
dictionary template
Definition: taskman.py:317
SG::ArenaHeapSTLAllocator::const_reference
const T & const_reference
Definition: ArenaHeapSTLAllocator.h:101
SG::ArenaHeapSTLAllocator::const_pointer
const T * const_pointer
Definition: ArenaHeapSTLAllocator.h:99
SG::ArenaNonConstHeapSTLAllocator::reserve
void reserve(size_t size)
Set the total number of elements cached by the allocator.
SG::ArenaHeapSTLAllocator< T, T >::base
std::allocator< T > base
Definition: ArenaHeapSTLAllocator.h:374
SG::ArenaHeapSTLAllocator::rebind
Standard STL allocator rebinder.
Definition: ArenaHeapSTLAllocator.h:115
SG::maybeUnprotect
void maybeUnprotect(ArenaHeapSTLAllocator< T, VETO > &a)
Hook for unprotecting an arena.
SG::ArenaHeapSTLAllocator_initParams::ArenaHeapSTLAllocator_initParams
ArenaHeapSTLAllocator_initParams(size_t nblock=1000, const std::string &name="")
Constructor.
SG::ArenaNonConstHeapSTLAllocator::erase
void erase()
Free all allocated elements and release memory back to the system.
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
Args
Definition: test_lwtnn_fastgraph.cxx:12
SG::ArenaHeapSTLAllocator< T, T >::value_type
base::value_type value_type
Standard STL allocator typedefs.
Definition: ArenaHeapSTLAllocator.h:377
x
#define x
SG::ArenaHeapSTLAllocator::select_on_container_copy_construction
ArenaHeapSTLAllocator select_on_container_copy_construction() const
Return allocator to use for a copy-constructed container.
SG::ArenaHeapSTLAllocator< T, T >::ArenaHeapSTLAllocator
ArenaHeapSTLAllocator(const ArenaHeapSTLAllocator< U, V > &a)
Constructor from another ArenaHeapSTLAllocator.
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SG::ArenaHeapSTLAllocator::deallocate
void deallocate(pointer, size_type n)
Deallocate objects.
SG::ArenaHeapSTLAllocator::pointer
T * pointer
Standard STL allocator typedefs.
Definition: ArenaHeapSTLAllocator.h:98
SG::ArenaAllocatorBase::Stats
Statistics for an allocator.
Definition: ArenaAllocatorBase.h:188
SG::ArenaHeapSTLAllocator::construct
void construct(pointer p, Args &&... args)
Call the T constructor.
beamspotman.n
n
Definition: beamspotman.py:731
SG::ArenaHeapSTLAllocator< T, T >::rebind::other
ArenaHeapSTLAllocator< U, T > other
Definition: ArenaHeapSTLAllocator.h:384
SG::ArenaHeapSTLAllocator< T, T >::difference_type
base::difference_type difference_type
Definition: ArenaHeapSTLAllocator.h:379
SG::ArenaNonConstHeapSTLAllocator::ArenaNonConstHeapSTLAllocator
ArenaNonConstHeapSTLAllocator(const ArenaHeapSTLAllocator< U, V > &a, ArenaBlockAllocatorBase *poolptr_nc)
Constructor.
SG::ArenaAllocatorBase
Common base class for arena allocator classes.
Definition: ArenaAllocatorBase.h:134
SG::ArenaHeapSTLAllocator_initParams
Initializer for pool allocator parameters.
Definition: ArenaHeapSTLAllocator.h:63
SG::ArenaHeapSTLAllocator::ArenaHeapSTLAllocator
ArenaHeapSTLAllocator(ArenaHeapSTLAllocator &&a)
Move constructor.
SG::ArenaHeapSTLAllocator::address
pointer address(reference x) const
Convert a reference to an address.
ArenaHeapSTLAllocator.icc
SG::ArenaHeapSTLAllocator::name
const std::string & name() const
Return the name of this allocator.
SG::ArenaHeapSTLAllocator::reserve
void reserve(size_t size)
Set the total number of elements cached by the allocator.
SG::ArenaHeapSTLAllocator< T, T >::name
const std::string & name() const
Return the name of this allocator.
SG::ArenaHeapSTLAllocator< T, T >::stats
ArenaAllocatorBase::Stats stats() const
Return the statistics block for this allocator.
SG::ArenaHeapSTLAllocator::ATH_MEMBER_REQUIRES
ATH_MEMBER_REQUIRES(!(std::is_same_v< reference, const_reference >), const_pointer) address(const_reference x) const
Definition: ArenaHeapSTLAllocator.h:204
SG::ArenaBlockAllocatorBase
Common functionality for block-oriented allocators.
Definition: ArenaBlockAllocatorBase.h:35
SG::ArenaHeapSTLAllocator::ArenaHeapSTLAllocator
ArenaHeapSTLAllocator(size_t nblock=1000, const std::string &name="")
Default constructor.
SG::ArenaHeapSTLAllocator::reference
T & reference
Definition: ArenaHeapSTLAllocator.h:100
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::ArenaHeapSTLAllocator::operator!=
bool operator!=(const ArenaHeapSTLAllocator &other) const
Inequality test.
SG::ArenaNonConstHeapSTLAllocator
Forward declaration.
Definition: ArenaHeapSTLAllocator.h:347
SG::ArenaHeapSTLAllocator::erase
void erase()
Free all allocated elements and release memory back to the system.
SG::ArenaHeapSTLAllocator< T, T >::nblock
size_t nblock() const
Return the hinted number of objects allocated per block.
SG::ArenaHeapSTLAllocator::m_pool
ArenaHeapAllocator m_pool
The underlying allocator.
Definition: ArenaHeapSTLAllocator.h:340
SG::ArenaHeapSTLAllocator::operator=
ArenaHeapSTLAllocator & operator=(ArenaHeapSTLAllocator &&a)
Move assignment.
SG::ArenaHeapSTLAllocator::difference_type
ptrdiff_t difference_type
Definition: ArenaHeapSTLAllocator.h:104
SG::ArenaHeapSTLAllocator::propagate_on_container_swap
std::true_type propagate_on_container_swap
Definition: ArenaHeapSTLAllocator.h:111
SG::ArenaHeapSTLAllocator< T, T >::m_poolptr
const ArenaBlockAllocatorBase * m_poolptr
Point at an underlying allocator from a different specialization.
Definition: ArenaHeapSTLAllocator.h:453
SG::ArenaHeapSTLAllocator::value_type
T value_type
Definition: ArenaHeapSTLAllocator.h:102
SG::ArenaHeapSTLAllocator::destroy
void destroy(pointer p)
Call the T destructor.
concepts.h
Compatibility helpers for using some pieces of C++20 concepts with older compilers.
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
SG::ArenaHeapSTLAllocator::stats
ArenaAllocatorBase::Stats stats() const
Return the statistics block for this allocator.
SG::ArenaHeapSTLAllocator::reset
void reset()
Free all allocated elements.
SG::ArenaHeapAllocator::initParams
Helper to initialize a parameters structure.
Definition: ArenaHeapAllocator.h:88
SG::ArenaHeapSTLAllocator::protect
void protect()
Write-protect the memory managed by this allocator.
SG::ArenaHeapSTLAllocator< T, T >::get_allocator
static ArenaNonConstHeapSTLAllocator< T > get_allocator(CONT &c)
Return an allocator supporting non-const methods from a non-const container reference.
SG::ArenaHeapSTLAllocator::poolptr
const ArenaBlockAllocatorBase * poolptr() const
Return a pointer to the underlying allocator (may be 0).
SG::ArenaHeapSTLAllocator< T, T >::ArenaHeapSTLAllocator
ArenaHeapSTLAllocator(size_t nblock=1000, const std::string &name="")
Default constructor.
SG::ArenaHeapSTLAllocator< T, T >::m_name
std::string m_name
Saved allocator name.
Definition: ArenaHeapSTLAllocator.h:450
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
SG::ArenaHeapSTLAllocator::propagate_on_container_copy_assignment
std::false_type propagate_on_container_copy_assignment
When we assign to a container, the target should retain its allocator.
Definition: ArenaHeapSTLAllocator.h:107
SG::ArenaHeapSTLAllocator::ArenaHeapSTLAllocator
ArenaHeapSTLAllocator(const ArenaHeapSTLAllocator &a)
Copy constructor.
checker_macros.h
Define macros for attributes used to control the static checker.
SG::ArenaHeapSTLAllocator::ArenaHeapSTLAllocator
ArenaHeapSTLAllocator(const ArenaHeapSTLAllocator< U, V > &a)
Constructor from another ArenaHeapSTLAllocator.
SG::ArenaNonConstHeapSTLAllocator::unprotect
void unprotect()
Write-enable the memory managed by this allocator.
SG::ArenaHeapSTLAllocator< T, T >::poolptr
const ArenaBlockAllocatorBase * poolptr() const
Return a pointer to the underlying allocator (may be 0).
SG::ArenaAllocatorBase::Params
Allocator parameters.
Definition: ArenaAllocatorBase.h:150
python.compressB64.c
def c
Definition: compressB64.py:93
SG::ArenaHeapSTLAllocator_initParams::Base
ArenaHeapAllocator::initParams< T, false, true, true > Base
We take defaults from this.
Definition: ArenaHeapSTLAllocator.h:66
SG::ArenaHeapSTLAllocator::unprotect
void unprotect()
Write-enable the memory managed by this allocator.
SG::ArenaHeapSTLAllocator::max_size
size_type max_size() const
Return the maximum number of objects we can allocate at once.
ArenaHeapAllocator.h
Heap-based allocator. See Arena.h for an overview of the arena-based memory allocators.
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
SG::ArenaNonConstHeapSTLAllocator::m_poolptr_nc
ArenaBlockAllocatorBase * m_poolptr_nc
Non-const pointer to the underlying allocator.
Definition: ArenaHeapSTLAllocator.h:540
SG::ArenaHeapSTLAllocator::swap
void swap(ArenaHeapSTLAllocator &a)
Swap.
SG::ArenaHeapSTLAllocator::nblock
size_t nblock() const
Return the hinted number of objects allocated per block.