Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ArenaPoolSTLAllocator.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-2025 CERN for the benefit of the ATLAS collaboration
4 */
52 #ifndef ATLALLOCATORS_ARENAPOOLSTLALLOCATOR
53 #define ATLALLOCATORS_ARENAPOOLSTLALLOCATOR
54 
55 
58 #include <string>
59 #include <type_traits>
60 #include <concepts>
61 
62 
63 namespace SG {
64 
65 
71 template <class T>
73  : public ArenaAllocatorBase::initParams<T, false, true, true>
74 {
75 public:
78 
86  ArenaPoolSTLAllocator_initParams (size_t nblock = 1000,
87  const std::string& name = "");
88 
91 
93  // Note: gcc 3.2.3 doesn't allow defining this out-of-line.
94  operator ArenaAllocatorBase::Params() const { return params(); }
95 };
96 
97 
104 template <class T, class VETO=T>
106 {
107 public:
109  typedef T* pointer;
110  typedef const T* const_pointer;
111  typedef T& reference;
112  typedef const T& const_reference;
113  typedef T value_type;
114  typedef size_t size_type;
115  typedef ptrdiff_t difference_type;
116 
118  typedef std::false_type propagate_on_container_copy_assignment;
119 
122  typedef std::true_type propagate_on_container_swap;
123 
124 
126  template <class U> struct rebind {
128  };
129 
130 
138  ArenaPoolSTLAllocator (size_t nblock = 1000, const std::string& name = "");
139 
140 
147 
148 
154  template <class U, class V>
156 
157 
158 
165 
166 
173 
174 
179 
180 
188 
189 
198 
199 
208 
209 
210  // We don't bother to supply a more general constructor --- shouldn't
211  // be needed.
212 
213 
216  template <bool = true>
217  requires (!std::same_as<reference,const_reference>)
219  address (const_reference x) const { return &x; }
220 
221 
227  pointer allocate (size_type n, const void* hint = 0);
228 
229 
237 
238 
244  size_type max_size() const throw();
245 
246 
252  template <class... Args>
253  void construct (pointer p, Args&&... args);
254 
255 
260  void destroy (pointer p);
261 
262 
266  size_t nblock() const;
267 
268 
272  const std::string& name() const;
273 
274 
283  void reset();
284 
285 
294  void erase();
295 
296 
314  void reserve (size_t size);
315 
316 
321 
322 
327 
328 
335  void protect();
336 
337 
344  void unprotect();
345 
346 
347 private:
350 };
351 
352 
353 
362 template <class T, class VETO>
363 class ArenaPoolSTLAllocator<T*, VETO>
364  : public std::allocator<T*>
365 {
366 public:
367  typedef std::allocator<T*> base;
368 
370  typedef typename base::value_type value_type;
371  typedef typename base::size_type size_type;
372  typedef typename base::difference_type difference_type;
373 
374 
376  template <class U> struct rebind {
378  };
379 
380 
388  ArenaPoolSTLAllocator(size_t nblock = 1000, const std::string& name = "");
389 
390 
396  template <class U, class V>
398 
399 
400  // We don't bother to supply a more general constructor --- shouldn't
401  // be needed.
402 
403 
407  size_t nblock() const;
408 
409 
413  const std::string& name() const;
414 
415 
416 private:
417  size_t m_nblock = 0;
418  std::string m_name;
419 };
420 
421 
423 template <class T>
425 
426 
445 template <class T>
447  typename std::enable_if<!std::is_pointer_v<T>, T>::type>
448  : public std::allocator<T>
449 {
450 public:
451  typedef std::allocator<T> base;
452 
454  typedef typename base::value_type value_type;
455  typedef typename base::size_type size_type;
456  typedef typename base::difference_type difference_type;
457 
458 
460  template <class U> struct rebind {
462  };
463 
464 
472  ArenaPoolSTLAllocator (size_t nblock = 1000, const std::string& name = "");
473 
474 
480  template <class U, class V>
482 
483 
484  // We don't bother to supply a more general constructor --- shouldn't
485  // be needed.
486 
487 
491  size_t nblock() const;
492 
493 
497  const std::string& name() const;
498 
499 
504 
505 
510 
511 
517  template <class CONT>
518  static
520 
521 
522 private:
524  size_t m_nblock = 0;
525 
527  std::string m_name;
528 
530  const ArenaBlockAllocatorBase* m_poolptr = nullptr;
531 };
532 
533 
534 
541 template <class T>
543  : public ArenaPoolSTLAllocator<T, T>
544 {
545 public:
551  template <class U, class V>
553  ArenaBlockAllocatorBase* poolptr_nc);
554 
555 
564  void reset();
565 
566 
575  void erase();
576 
577 
595  void reserve (size_t size);
596 
597 
604  void protect();
605 
606 
613  void unprotect();
614 
615 
616 private:
619 };
620 
621 
630 template <class T, class VETO>
632 
633 
634 } // namespace SG
635 
636 
638 
639 
640 #endif // ATLALLOCATORS_ARENAPOOLSTLALLOCATOR
SG::ArenaPoolSTLAllocator< T *, VETO >::ArenaPoolSTLAllocator
ArenaPoolSTLAllocator(size_t nblock=1000, const std::string &name="")
Default constructor.
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::get_allocator
static ArenaNonConstPoolSTLAllocator< T > get_allocator(CONT &c)
Return an allocator supporting non-const methods from a non-const container reference.
SG::ArenaPoolSTLAllocator::poolptr
const ArenaBlockAllocatorBase * poolptr() const
Return a pointer to the underlying allocator (may be 0).
SG::ArenaPoolSTLAllocator< T *, VETO >::size_type
base::size_type size_type
Definition: ArenaPoolSTLAllocator.h:371
SG::ArenaNonConstPoolSTLAllocator
Forward declaration.
Definition: ArenaPoolSTLAllocator.h:424
SG::ArenaPoolAllocator
Pool-based allocator.
Definition: ArenaPoolAllocator.h:40
SG::ArenaPoolSTLAllocator::reserve
void reserve(size_t size)
Set the total number of elements cached by the allocator.
ArenaPoolSTLAllocator.icc
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::ArenaPoolSTLAllocator_initParams::ArenaPoolSTLAllocator_initParams
ArenaPoolSTLAllocator_initParams(size_t nblock=1000, const std::string &name="")
Constructor.
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::difference_type
base::difference_type difference_type
Definition: ArenaPoolSTLAllocator.h:456
python.CaloAddPedShiftConfig.args
args
Definition: CaloAddPedShiftConfig.py:45
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::size_type
base::size_type size_type
Definition: ArenaPoolSTLAllocator.h:455
SG::ArenaPoolSTLAllocator::protect
void protect()
Write-protect the memory managed by this allocator.
SG::ArenaPoolSTLAllocator::nblock
size_t nblock() const
Return the hinted number of objects allocated per block.
SG::ArenaNonConstPoolSTLAllocator::ArenaNonConstPoolSTLAllocator
ArenaNonConstPoolSTLAllocator(const ArenaPoolSTLAllocator< U, V > &a, ArenaBlockAllocatorBase *poolptr_nc)
Constructor.
SG::ArenaNonConstPoolSTLAllocator::reset
void reset()
Free all allocated elements.
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::value_type
base::value_type value_type
Standard STL allocator typedefs.
Definition: ArenaPoolSTLAllocator.h:454
taskman.template
dictionary template
Definition: taskman.py:317
SG::ArenaPoolSTLAllocator< T *, VETO >::rebind::other
ArenaPoolSTLAllocator< U, VETO > other
Definition: ArenaPoolSTLAllocator.h:377
SG::maybeUnprotect
void maybeUnprotect(ArenaHeapSTLAllocator< T, VETO > &a)
Hook for unprotecting an arena.
SG::ArenaPoolSTLAllocator::value_type
T value_type
Definition: ArenaPoolSTLAllocator.h:113
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
Args
Definition: test_lwtnn_fastgraph.cxx:12
x
#define x
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
SG::ArenaPoolSTLAllocator::m_pool
ArenaPoolAllocator m_pool
The underlying allocator.
Definition: ArenaPoolSTLAllocator.h:349
SG::ArenaPoolSTLAllocator::deallocate
void deallocate(pointer, size_type n)
Deallocate objects.
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::ArenaPoolSTLAllocator
ArenaPoolSTLAllocator(const ArenaPoolSTLAllocator< U, V > &a)
Constructor from another ArenaPoolSTLAllocator.
SG::ArenaPoolSTLAllocator::ArenaPoolSTLAllocator
ArenaPoolSTLAllocator(size_t nblock=1000, const std::string &name="")
Default constructor.
SG::ArenaPoolSTLAllocator::name
const std::string & name() const
Return the name of this allocator.
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::name
const std::string & name() const
Return the name of this allocator.
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
SG::ArenaPoolSTLAllocator::allocate
pointer allocate(size_type n, const void *hint=0)
Allocate new objects.
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::nblock
size_t nblock() const
Return the hinted number of objects allocated per block.
SG::ArenaAllocatorBase::Stats
Statistics for an allocator.
Definition: ArenaAllocatorBase.h:188
SG::ArenaPoolSTLAllocator::propagate_on_container_swap
std::true_type propagate_on_container_swap
Definition: ArenaPoolSTLAllocator.h:122
SG::ArenaPoolSTLAllocator::erase
void erase()
Free all allocated elements and release memory back to the system.
SG::ArenaPoolSTLAllocator< T *, VETO >::name
const std::string & name() const
Return the name of this allocator.
SG::ArenaPoolSTLAllocator::select_on_container_copy_construction
ArenaPoolSTLAllocator select_on_container_copy_construction() const
Return allocator to use for a copy-constructed container.
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::poolptr
const ArenaBlockAllocatorBase * poolptr() const
Return a pointer to the underlying allocator (may be 0).
SG::ArenaPoolSTLAllocator< T *, VETO >::m_name
std::string m_name
Definition: ArenaPoolSTLAllocator.h:418
SG::ArenaPoolSTLAllocator::const_pointer
const T * const_pointer
Definition: ArenaPoolSTLAllocator.h:110
beamspotman.n
n
Definition: beamspotman.py:731
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::ArenaPoolSTLAllocator
ArenaPoolSTLAllocator(size_t nblock=1000, const std::string &name="")
Default constructor.
SG::ArenaPoolSTLAllocator_initParams::Base
ArenaAllocatorBase::initParams< T, false, true, true > Base
We take defaults from this.
Definition: ArenaPoolSTLAllocator.h:77
SG::ArenaPoolSTLAllocator::destroy
void destroy(pointer p)
Call the T destructor.
SG::ArenaAllocatorBase
Common base class for arena allocator classes.
Definition: ArenaAllocatorBase.h:134
SG::ArenaPoolSTLAllocator< T *, VETO >::nblock
size_t nblock() const
Return the hinted number of objects allocated per block.
SG::ArenaPoolSTLAllocator::reference
T & reference
Definition: ArenaPoolSTLAllocator.h:111
SG::ArenaPoolSTLAllocator::requires
requires(!std::same_as< reference, const_reference >) const _pointer address(const_reference x) const
Definition: ArenaPoolSTLAllocator.h:217
SG::ArenaPoolSTLAllocator::const_reference
const T & const_reference
Definition: ArenaPoolSTLAllocator.h:112
SG::ArenaPoolSTLAllocator< T *, VETO >::ArenaPoolSTLAllocator
ArenaPoolSTLAllocator(const ArenaPoolSTLAllocator< U, V > &a)
Constructor from another ArenaPoolSTLAllocator.
SG::ArenaBlockAllocatorBase
Common functionality for block-oriented allocators.
Definition: ArenaBlockAllocatorBase.h:35
SG::ArenaPoolSTLAllocator::ArenaPoolSTLAllocator
ArenaPoolSTLAllocator(const ArenaPoolSTLAllocator< U, V > &a)
Constructor from another ArenaPoolSTLAllocator.
SG::ArenaPoolSTLAllocator::construct
void construct(pointer p, Args &&... args)
Call the T constructor.
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::rebind::other
ArenaPoolSTLAllocator< U, T > other
Definition: ArenaPoolSTLAllocator.h:461
SG::ArenaPoolSTLAllocator::difference_type
ptrdiff_t difference_type
Definition: ArenaPoolSTLAllocator.h:115
SG::ArenaPoolSTLAllocator::unprotect
void unprotect()
Write-enable the memory managed by this allocator.
SG::ArenaPoolSTLAllocator::max_size
size_type max_size() const
Return the maximum number of objects we can allocate at once.
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ArenaPoolAllocator.h
Pool-based allocator. See Arena.h for an overview of the arena-based memory allocators.
SG::ArenaPoolSTLAllocator< T *, VETO >::value_type
base::value_type value_type
Standard STL allocator typedefs.
Definition: ArenaPoolSTLAllocator.h:370
SG::ArenaPoolSTLAllocator< T *, VETO >::base
std::allocator< T * > base
Definition: ArenaPoolSTLAllocator.h:367
SG::ArenaPoolSTLAllocator::reset
void reset()
Free all allocated elements.
SG::ArenaNonConstPoolSTLAllocator::reserve
void reserve(size_t size)
Set the total number of elements cached by the allocator.
python.Dumpers.typename
def typename(t)
Definition: Dumpers.py:194
SG::ArenaNonConstPoolSTLAllocator::erase
void erase()
Free all allocated elements and release memory back to the system.
SG::ArenaPoolSTLAllocator::operator!=
bool operator!=(const ArenaPoolSTLAllocator &other) const
Inequality test.
SG::ArenaPoolSTLAllocator::ArenaPoolSTLAllocator
ArenaPoolSTLAllocator(const ArenaPoolSTLAllocator &a)
Copy constructor.
SG::ArenaPoolSTLAllocator::stats
ArenaAllocatorBase::Stats stats() const
Return the statistics block for this allocator.
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::m_name
std::string m_name
Saved allocator name.
Definition: ArenaPoolSTLAllocator.h:527
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::base
std::allocator< T > base
Definition: ArenaPoolSTLAllocator.h:451
SG::ArenaNonConstPoolSTLAllocator::m_poolptr_nc
ArenaBlockAllocatorBase * m_poolptr_nc
Non-const pointer to the underlying allocator.
Definition: ArenaPoolSTLAllocator.h:618
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
SG::ArenaPoolSTLAllocator::operator=
ArenaPoolSTLAllocator & operator=(ArenaPoolSTLAllocator &&a)
Move assignment.
SG::ArenaPoolSTLAllocator
STL-style allocator wrapper for ArenaPoolAllocator.
Definition: ArenaPoolSTLAllocator.h:106
SG::ArenaPoolSTLAllocator::ArenaPoolSTLAllocator
ArenaPoolSTLAllocator(ArenaPoolSTLAllocator &&a)
Move constructor.
SG::ArenaPoolSTLAllocator::swap
void swap(ArenaPoolSTLAllocator &a)
Swap.
SG::ArenaPoolSTLAllocator::operator==
bool operator==(const ArenaPoolSTLAllocator &other) const
Equality test.
SG::ArenaPoolSTLAllocator::propagate_on_container_move_assignment
std::true_type propagate_on_container_move_assignment
Move allocators on move/swap.
Definition: ArenaPoolSTLAllocator.h:121
SG::ArenaPoolSTLAllocator::pointer
T * pointer
Standard STL allocator typedefs.
Definition: ArenaPoolSTLAllocator.h:109
SG::ArenaAllocatorBase::initParams
Helper to initialize a parameters structure.
Definition: ArenaAllocatorBase.h:316
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::stats
ArenaAllocatorBase::Stats stats() const
Return the statistics block for this allocator.
SG::ArenaPoolSTLAllocator_initParams::params
ArenaAllocatorBase::Params params() const
Return an initialized parameters structure.
SG::ArenaNonConstPoolSTLAllocator::protect
void protect()
Write-protect the memory managed by this allocator.
SG::ArenaPoolSTLAllocator::size_type
size_t size_type
Definition: ArenaPoolSTLAllocator.h:114
SG::ArenaPoolSTLAllocator< T *, VETO >::difference_type
base::difference_type difference_type
Definition: ArenaPoolSTLAllocator.h:372
checker_macros.h
Define macros for attributes used to control the static checker.
SG::ArenaPoolSTLAllocator_initParams
Initializer for pool allocator parameters.
Definition: ArenaPoolSTLAllocator.h:74
SG::ArenaPoolSTLAllocator::address
pointer address(reference x) const
Convert a reference to an address.
SG::ArenaAllocatorBase::Params
Allocator parameters.
Definition: ArenaAllocatorBase.h:150
python.compressB64.c
def c
Definition: compressB64.py:93
SG::ArenaPoolSTLAllocator::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: ArenaPoolSTLAllocator.h:118
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
SG::ArenaPoolSTLAllocator::rebind
Standard STL allocator rebinder.
Definition: ArenaPoolSTLAllocator.h:126
SG::ArenaNonConstPoolSTLAllocator::unprotect
void unprotect()
Write-enable the memory managed by this allocator.
SG::ArenaPoolSTLAllocator::rebind::other
ArenaPoolSTLAllocator< U, VETO > other
Definition: ArenaPoolSTLAllocator.h:127