ATLAS Offline Software
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-2024 CERN for the benefit of the ATLAS collaboration
4 */
52 #ifndef ATLALLOCATORS_ARENAPOOLSTLALLOCATOR
53 #define ATLALLOCATORS_ARENAPOOLSTLALLOCATOR
54 
55 
57 #include "CxxUtils/concepts.h"
59 #include <string>
60 #include <type_traits>
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  ATH_MEMBER_REQUIRES(!(std::is_same_v<reference,const_reference>),
218  address (const_reference x) const { return &x; }
219 
220 
226  pointer allocate (size_type n, const void* hint = 0);
227 
228 
236 
237 
243  size_type max_size() const throw();
244 
245 
251  template <class... Args>
252  void construct (pointer p, Args&&... args);
253 
254 
259  void destroy (pointer p);
260 
261 
265  size_t nblock() const;
266 
267 
271  const std::string& name() const;
272 
273 
282  void reset();
283 
284 
293  void erase();
294 
295 
313  void reserve (size_t size);
314 
315 
320 
321 
326 
327 
334  void protect();
335 
336 
343  void unprotect();
344 
345 
346 private:
349 };
350 
351 
352 
361 template <class T, class VETO>
362 class ArenaPoolSTLAllocator<T*, VETO>
363  : public std::allocator<T*>
364 {
365 public:
366  typedef std::allocator<T*> base;
367 
369  typedef typename base::value_type value_type;
370  typedef typename base::size_type size_type;
371  typedef typename base::difference_type difference_type;
372 
373 
375  template <class U> struct rebind {
377  };
378 
379 
387  ArenaPoolSTLAllocator(size_t nblock = 1000, const std::string& name = "");
388 
389 
395  template <class U, class V>
397 
398 
399  // We don't bother to supply a more general constructor --- shouldn't
400  // be needed.
401 
402 
406  size_t nblock() const;
407 
408 
412  const std::string& name() const;
413 
414 
415 private:
416  size_t m_nblock = 0;
417  std::string m_name;
418 };
419 
420 
422 template <class T>
424 
425 
444 template <class T>
446  typename std::enable_if<!std::is_pointer_v<T>, T>::type>
447  : public std::allocator<T>
448 {
449 public:
450  typedef std::allocator<T> base;
451 
453  typedef typename base::value_type value_type;
454  typedef typename base::size_type size_type;
455  typedef typename base::difference_type difference_type;
456 
457 
459  template <class U> struct rebind {
461  };
462 
463 
471  ArenaPoolSTLAllocator (size_t nblock = 1000, const std::string& name = "");
472 
473 
479  template <class U, class V>
481 
482 
483  // We don't bother to supply a more general constructor --- shouldn't
484  // be needed.
485 
486 
490  size_t nblock() const;
491 
492 
496  const std::string& name() const;
497 
498 
503 
504 
509 
510 
516  template <class CONT>
517  static
519 
520 
521 private:
523  size_t m_nblock = 0;
524 
526  std::string m_name;
527 
529  const ArenaBlockAllocatorBase* m_poolptr = nullptr;
530 };
531 
532 
533 
540 template <class T>
542  : public ArenaPoolSTLAllocator<T, T>
543 {
544 public:
550  template <class U, class V>
552  ArenaBlockAllocatorBase* poolptr_nc);
553 
554 
563  void reset();
564 
565 
574  void erase();
575 
576 
594  void reserve (size_t size);
595 
596 
603  void protect();
604 
605 
612  void unprotect();
613 
614 
615 private:
618 };
619 
620 
629 template <class T, class VETO>
631 
632 
633 } // namespace SG
634 
635 
637 
638 
639 #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:370
SG::ArenaNonConstPoolSTLAllocator
Forward declaration.
Definition: ArenaPoolSTLAllocator.h:423
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:455
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::size_type
base::size_type size_type
Definition: ArenaPoolSTLAllocator.h:454
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:453
taskman.template
dictionary template
Definition: taskman.py:317
SG::ArenaPoolSTLAllocator< T *, VETO >::rebind::other
ArenaPoolSTLAllocator< U, VETO > other
Definition: ArenaPoolSTLAllocator.h:376
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
SG::ArenaPoolSTLAllocator::m_pool
ArenaPoolAllocator m_pool
The underlying allocator.
Definition: ArenaPoolSTLAllocator.h:348
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:417
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::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:460
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:369
SG::ArenaPoolSTLAllocator< T *, VETO >::base
std::allocator< T * > base
Definition: ArenaPoolSTLAllocator.h:366
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:526
SG::ArenaPoolSTLAllocator< T, typename std::enable_if<!std::is_pointer_v< T >, T >::type >::base
std::allocator< T > base
Definition: ArenaPoolSTLAllocator.h:450
concepts.h
Compatibility helpers for using some pieces of C++20 concepts with older compilers.
SG::ArenaNonConstPoolSTLAllocator::m_poolptr_nc
ArenaBlockAllocatorBase * m_poolptr_nc
Non-const pointer to the underlying allocator.
Definition: ArenaPoolSTLAllocator.h:617
SG::ArenaPoolSTLAllocator::ATH_MEMBER_REQUIRES
ATH_MEMBER_REQUIRES(!(std::is_same_v< reference, const_reference >), const_pointer) address(const_reference x) const
Definition: ArenaPoolSTLAllocator.h:216
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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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:371
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
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
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