ATLAS Offline Software
ArenaSharedHeapSTLAllocator.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-2021 CERN for the benefit of the ATLAS collaboration
4 */
59 #ifndef ATLALLOCATORS_ARENASHAREDHEAPSTLALLOCATOR_H
60 #define ATLALLOCATORS_ARENASHAREDHEAPSTLALLOCATOR_H
61 
62 
66 #include "CxxUtils/concepts.h"
67 #include <string>
68 #include <vector>
69 
70 
71 namespace SG {
72 
74 template <class T>
76 
77 
91 {
92 public:
99  ArenaSharedHeapSTLHeader (const void* owner, int nblock);
100 
101 
108 
109 
117  void maybe_delete (const void* a);
118 
119 
124 
125 
129  template <class T>
130  static std::string get_name();
131 
132 
136  template <class T>
138 
139 
147  void update_owner (const void* old_owner, const void* new_owner);
148 
149 
154  void report (std::ostream& os) const;
155 
156 
163  void protect();
164 
165 
172  void unprotect();
173 
174 
175 private:
179  template <class T>
180  static size_t get_index();
181 
183  const void* m_owner;
184 
186  size_t m_nblock;
187 
189  std::vector<ArenaHeapAllocator*> m_allocators;
190 };
191 
192 
193 
194 
201 template <class T>
203 {
204 public:
207  template <class U> friend class ArenaSharedHeapSTLAllocator;
208 
210  typedef T* pointer;
211  typedef const T* const_pointer;
212  typedef T& reference;
213  typedef const T& const_reference;
214  typedef T value_type;
215  typedef size_t size_type;
216  typedef ptrdiff_t difference_type;
217 
219  typedef std::false_type propagate_on_container_copy_assignment;
220 
223  typedef std::true_type propagate_on_container_swap;
224 
225 
227  template <class U> struct rebind {
229  };
230 
231 
238 
239 
247 
248 
251 
252 
259  template <class U>
261 
262 
263  // We don't bother to supply a more general constructor --- shouldn't
264  // be needed.
265 
266 
271 
272 
282 
283 
290 
291 
296 
297 
306 
307 
316 
317 
320  ATH_MEMBER_REQUIRES(!(std::is_same_v<reference,const_reference>),
322  address (const_reference x) const { return &x; }
323 
324 
330  pointer allocate (size_type n, const void* hint = 0);
331 
332 
338  ATH_MEMBER_REQUIRES(!(std::is_same_v<pointer,const_pointer>), void)
340  {
341  pointer p_nc ATLAS_THREAD_SAFE = const_cast<pointer>(p);
342  deallocate (p_nc, n);
343  }
344 
345 
351  size_type max_size() const throw();
352 
353 
359  template <class... Args>
360  void construct (pointer p, Args&&... args);
361 
362 
367  void destroy (pointer p);
368 
369 
373  size_t nblock() const;
374 
375 
379  const std::string& name() const;
380 
381 
390  void reset();
391 
392 
401  void erase();
402 
403 
421  void reserve (size_t size);
422 
423 
428 
429 
435 
436 
441 
442 
447 
448 
453  void report (std::ostream& os) const;
454 
455 
462  void protect();
463 
464 
471  void unprotect();
472 
473 
474 private:
477 };
478 
479 
480 template <class T>
482 {
483  a.swap (b);
484 }
485 
486 
495 template <class T>
497 
498 
499 } // namespace SG
500 
501 
503 
504 
505 #endif // not ATLALLOCATORS_ARENASHAREDHEAPSTLALLOCATOR_H
SG::ArenaSharedHeapSTLAllocator::ArenaSharedHeapSTLAllocator
ArenaSharedHeapSTLAllocator(ArenaSharedHeapSTLAllocator &&a)=default
Move constructor is the same as the copy constructor.
SG::ArenaSharedHeapSTLAllocator::allocate
pointer allocate(size_type n, const void *hint=0)
Allocate new objects.
SG::ArenaSharedHeapSTLHeader::m_owner
const void * m_owner
Address of the allocator that created this header.
Definition: ArenaSharedHeapSTLAllocator.h:183
SG::ArenaSharedHeapSTLHeader::~ArenaSharedHeapSTLHeader
~ArenaSharedHeapSTLHeader()
Destructor.
Definition: ArenaSharedHeapSTLAllocator.cxx:39
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::ArenaSharedHeapSTLAllocator::rebind::other
ArenaSharedHeapSTLAllocator< U > other
Definition: ArenaSharedHeapSTLAllocator.h:228
SG::ArenaSharedHeapSTLAllocator::operator!=
bool operator!=(const ArenaSharedHeapSTLAllocator &other) const
Inequality test.
SG::ArenaSharedHeapSTLHeader::protect
void protect()
Write-protect the memory managed by these allocators.
Definition: ArenaSharedHeapSTLAllocator.cxx:82
SG::ArenaSharedHeapSTLAllocator::~ArenaSharedHeapSTLAllocator
~ArenaSharedHeapSTLAllocator()
Destructor.
SG::ArenaSharedHeapSTLAllocator::reserve
void reserve(size_t size)
Set the total number of elements cached by the allocator.
SG::ArenaHeapAllocator
Heap-based allocator.
Definition: ArenaHeapAllocator.h:64
SG::ArenaSharedHeapSTLHeader
Common header class for ArenaSharedHeapSTLAllocator.
Definition: ArenaSharedHeapSTLAllocator.h:91
SG::ArenaSharedHeapSTLHeader::get_name
static std::string get_name()
Return the name to use for an allocator for type T.
taskman.template
dictionary template
Definition: taskman.py:317
SG::ArenaSharedHeapSTLAllocator::construct
void construct(pointer p, Args &&... args)
Call the T constructor.
SG::ArenaSharedHeapSTLAllocator::destroy
void destroy(pointer p)
Call the T destructor.
SG::maybeUnprotect
void maybeUnprotect(ArenaHeapSTLAllocator< T, VETO > &a)
Hook for unprotecting an arena.
SG::ArenaSharedHeapSTLHeader::get_index
static size_t get_index()
Return the allocator index to use for type T.
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
Args
Definition: test_lwtnn_fastgraph.cxx:12
SG::ArenaSharedHeapSTLHeader::get_pool
ArenaHeapAllocator * get_pool()
Return the heap allocator for type T.
SG::ArenaSharedHeapSTLAllocator::reset
void reset()
Free all allocated elements.
x
#define x
SG::ArenaSharedHeapSTLAllocator::ArenaSharedHeapSTLAllocator
ArenaSharedHeapSTLAllocator(size_t nblock=1000)
Default constructor.
SG::ArenaSharedHeapSTLAllocator::difference_type
ptrdiff_t difference_type
Definition: ArenaSharedHeapSTLAllocator.h:216
SG::ArenaSharedHeapSTLAllocator::name
const std::string & name() const
Return the name of this allocator.
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
SG::ArenaSharedHeapSTLAllocator::poolptr
ArenaHeapAllocator * poolptr()
Return a pointer to the underlying allocator.
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SG::ArenaSharedHeapSTLAllocator::max_size
size_type max_size() const
Return the maximum number of objects we can allocate at once.
SG::ArenaAllocatorBase::Stats
Statistics for an allocator.
Definition: ArenaAllocatorBase.h:188
SG::ArenaSharedHeapSTLAllocator::size_type
size_t size_type
Definition: ArenaSharedHeapSTLAllocator.h:215
SG::ArenaSharedHeapSTLAllocator::protect
void protect()
Write-protect the memory managed by these allocators.
SG::ArenaSharedHeapSTLAllocator::operator==
bool operator==(const ArenaSharedHeapSTLAllocator &other) const
Equality test.
beamspotman.n
n
Definition: beamspotman.py:731
SG::ArenaSharedHeapSTLAllocator::propagate_on_container_move_assignment
std::true_type propagate_on_container_move_assignment
Move allocators on move/swap.
Definition: ArenaSharedHeapSTLAllocator.h:222
SG::ArenaAllocatorBase
Common base class for arena allocator classes.
Definition: ArenaAllocatorBase.h:134
SG::ArenaSharedHeapSTLAllocator::erase
void erase()
Free all allocated elements and release memory back to the system.
SG::ArenaSharedHeapSTLAllocator::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: ArenaSharedHeapSTLAllocator.h:219
SG::ArenaSharedHeapSTLAllocator::address
pointer address(reference x) const
Convert a reference to an address.
SG::ArenaSharedHeapSTLAllocator::rebind
Standard STL allocator rebinder.
Definition: ArenaSharedHeapSTLAllocator.h:227
SG::ArenaSharedHeapSTLAllocator::ATH_MEMBER_REQUIRES
ATH_MEMBER_REQUIRES(!(std::is_same_v< reference, const_reference >), const_pointer) address(const_reference x) const
Definition: ArenaSharedHeapSTLAllocator.h:320
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
SG::ArenaSharedHeapSTLAllocator::ArenaSharedHeapSTLAllocator
ArenaSharedHeapSTLAllocator(const ArenaSharedHeapSTLAllocator< U > &a)
Constructor from another ArenaSharedHeapSTLAllocator.
SG::ArenaSharedHeapSTLAllocator::operator=
ArenaSharedHeapSTLAllocator & operator=(const ArenaSharedHeapSTLAllocator &a)
Assignment.
SG::ArenaSharedHeapSTLAllocator::const_pointer
const T * const_pointer
Definition: ArenaSharedHeapSTLAllocator.h:211
SG::ArenaSharedHeapSTLAllocator::reference
T & reference
Definition: ArenaSharedHeapSTLAllocator.h:212
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
SG::ArenaSharedHeapSTLHeader::maybe_delete
void maybe_delete(const void *a)
Call this when an allocator is being deleted.
SG::ArenaSharedHeapSTLHeader::m_allocators
std::vector< ArenaHeapAllocator * > m_allocators
List of allocators.
Definition: ArenaSharedHeapSTLAllocator.h:189
SG::ArenaSharedHeapSTLAllocator::nblock
size_t nblock() const
Return the hinted number of objects allocated per block.
concepts.h
Compatibility helpers for using some pieces of C++20 concepts with older compilers.
ArenaSharedHeapSTLAllocator.icc
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
SG::ArenaSharedHeapSTLHeader::m_nblock
size_t m_nblock
Saved value for nblock parameter.
Definition: ArenaSharedHeapSTLAllocator.h:186
SG::ArenaSharedHeapSTLAllocator::report
void report(std::ostream &os) const
Generate printable report for all contained allocators.
SG::ArenaSharedHeapSTLAllocator::ArenaSharedHeapSTLAllocator
ArenaSharedHeapSTLAllocator(const ArenaSharedHeapSTLAllocator &a)
Copy constructor.
SG::ArenaSharedHeapSTLHeader::ArenaSharedHeapSTLHeader
ArenaSharedHeapSTLHeader(const void *owner, int nblock)
Constructor.
Definition: ArenaSharedHeapSTLAllocator.cxx:26
SG::ArenaSharedHeapSTLAllocator::propagate_on_container_swap
std::true_type propagate_on_container_swap
Definition: ArenaSharedHeapSTLAllocator.h:223
SG::ArenaSharedHeapSTLAllocator::stats
ArenaAllocatorBase::Stats stats() const
Return the statistics block for this allocator.
SG::ArenaSharedHeapSTLAllocator::m_pool
ArenaHeapAllocator * m_pool
Definition: ArenaSharedHeapSTLAllocator.h:476
SG::ArenaSharedHeapSTLAllocator::swap
void swap(ArenaSharedHeapSTLAllocator &a)
Swap.
SG::ArenaSharedHeapSTLAllocator::unprotect
void unprotect()
Write-enable the memory managed by these allocators.
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
SG::ArenaSharedHeapSTLAllocator::value_type
T value_type
Definition: ArenaSharedHeapSTLAllocator.h:214
SG::ArenaSharedHeapSTLAllocator::m_header
ArenaSharedHeapSTLHeader * m_header
Definition: ArenaSharedHeapSTLAllocator.h:475
ArenaAllocatorRegistry.h
Registry of allocator factories. See Arena.h for an overview of the arena-based memory allocators.
SG::ArenaSharedHeapSTLAllocator::deallocate
void deallocate(pointer, size_type n)
Deallocate objects.
ArenaHeapSTLAllocator.h
STL-style allocator wrapper for ArenaHeapAllocator.
SG::ArenaSharedHeapSTLAllocator::totstats
ArenaAllocatorBase::Stats totstats() const
Return the statistics blocks summed up over all allocators using this pool.
SG::ArenaSharedHeapSTLHeader::update_owner
void update_owner(const void *old_owner, const void *new_owner)
Update the owner of this object.
SG::ArenaSharedHeapSTLHeader::unprotect
void unprotect()
Write-enable the memory managed by these allocators.
Definition: ArenaSharedHeapSTLAllocator.cxx:98
ArenaHeapAllocator.h
Heap-based allocator. See Arena.h for an overview of the arena-based memory allocators.
SG::ArenaSharedHeapSTLHeader::report
void report(std::ostream &os) const
Generate printable report for all contained allocators.
Definition: ArenaSharedHeapSTLAllocator.cxx:67
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
SG::ArenaSharedHeapSTLHeader::totstats
ArenaAllocatorBase::Stats totstats() const
Return allocator statistics summed over all our owned allocators.
Definition: ArenaSharedHeapSTLAllocator.cxx:51
SG::ArenaSharedHeapSTLAllocator
Forward declaration.
Definition: ArenaSharedHeapSTLAllocator.h:75
SG::ArenaSharedHeapSTLAllocator::pointer
T * pointer
Standard STL allocator typedefs.
Definition: ArenaSharedHeapSTLAllocator.h:210
SG::ArenaSharedHeapSTLAllocator::const_reference
const T & const_reference
Definition: ArenaSharedHeapSTLAllocator.h:213