ATLAS Offline Software
Loading...
Searching...
No Matches
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*/
50
51
52#ifndef ATLALLOCATORS_ARENAPOOLSTLALLOCATOR
53#define ATLALLOCATORS_ARENAPOOLSTLALLOCATOR
54
55
58#include <string>
59#include <type_traits>
60#include <concepts>
61
62
63namespace SG {
64
65
71template <class T>
73 : public ArenaAllocatorBase::initParams<T, false, true, true>
74{
75public:
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
104template <class T, class VETO=T>
106{
107public:
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
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
197 bool operator== (const ArenaPoolSTLAllocator& other) const;
198
199
207 bool operator!= (const ArenaPoolSTLAllocator& other) const;
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
347private:
350};
351
352
353
362template <class T, class VETO>
364 : public std::allocator<T*>
365{
366public:
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
416private:
417 size_t m_nblock = 0;
418 std::string m_name;
419};
420
421
423template <class T>
425
426
445template <class T>
447 typename std::enable_if<!std::is_pointer_v<T>, T>::type>
448 : public std::allocator<T>
449{
450public:
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
522private:
524 size_t m_nblock = 0;
525
527 std::string m_name;
528
531};
532
533
534
541template <class T>
543 : public ArenaPoolSTLAllocator<T, T>
544{
545public:
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
616private:
619};
620
621
630template <class T, class VETO>
632
633
634} // namespace SG
635
636
638
639
640#endif // ATLALLOCATORS_ARENAPOOLSTLALLOCATOR
Pool-based allocator. See Arena.h for an overview of the arena-based memory allocators.
static Double_t a
#define x
Define macros for attributes used to control the static checker.
Common base class for arena allocator classes.
Common functionality for block-oriented allocators.
ArenaNonConstPoolSTLAllocator(const ArenaPoolSTLAllocator< U, V > &a, ArenaBlockAllocatorBase *poolptr_nc)
Constructor.
void erase()
Free all allocated elements and release memory back to the system.
void unprotect()
Write-enable the memory managed by this allocator.
ArenaBlockAllocatorBase * m_poolptr_nc
Non-const pointer to the underlying allocator.
void reset()
Free all allocated elements.
void reserve(size_t size)
Set the total number of elements cached by the allocator.
void protect()
Write-protect the memory managed by this allocator.
Pool-based allocator.
size_t nblock() const
Return the hinted number of objects allocated per block.
ArenaPoolSTLAllocator(const ArenaPoolSTLAllocator< U, V > &a)
Constructor from another ArenaPoolSTLAllocator.
ArenaAllocatorBase::Stats stats() const
Return the statistics block for this allocator.
ArenaPoolSTLAllocator(size_t nblock=1000, const std::string &name="")
Default constructor.
const ArenaBlockAllocatorBase * m_poolptr
Point at an underlying allocator from a different specialization.
static ArenaNonConstPoolSTLAllocator< T > get_allocator(CONT &c)
Return an allocator supporting non-const methods from a non-const container reference.
const std::string & name() const
Return the name of this allocator.
const ArenaBlockAllocatorBase * poolptr() const
Return a pointer to the underlying allocator (may be 0).
ArenaPoolSTLAllocator(size_t nblock=1000, const std::string &name="")
Default constructor.
const std::string & name() const
Return the name of this allocator.
size_t nblock() const
Return the hinted number of objects allocated per block.
ArenaPoolSTLAllocator(const ArenaPoolSTLAllocator< U, V > &a)
Constructor from another ArenaPoolSTLAllocator.
base::value_type value_type
Standard STL allocator typedefs.
ArenaAllocatorBase::initParams< T, false, true, true > Base
We take defaults from this.
ArenaAllocatorBase::Params params() const
Return an initialized parameters structure.
ArenaPoolSTLAllocator_initParams(size_t nblock=1000, const std::string &name="")
Constructor.
STL-style allocator wrapper for ArenaPoolAllocator.
ArenaPoolSTLAllocator select_on_container_copy_construction() const
Return allocator to use for a copy-constructed container.
bool operator==(const ArenaPoolSTLAllocator &other) const
Equality test.
void construct(pointer p, Args &&... args)
ArenaPoolSTLAllocator(const ArenaPoolSTLAllocator &a)
Copy constructor.
ArenaPoolSTLAllocator(size_t nblock=1000, const std::string &name="")
Default constructor.
pointer address(reference x) const
Convert a reference to an address.
pointer allocate(size_type n, const void *hint=0)
Allocate new objects.
ArenaPoolSTLAllocator(ArenaPoolSTLAllocator &&a)
Move constructor.
bool operator!=(const ArenaPoolSTLAllocator &other) const
Inequality test.
T * pointer
Standard STL allocator typedefs.
size_type max_size() const
Return the maximum number of objects we can allocate at once.
void swap(ArenaPoolSTLAllocator &a)
Swap.
const ArenaBlockAllocatorBase * poolptr() const
std::true_type propagate_on_container_move_assignment
Move allocators on move/swap.
ArenaPoolSTLAllocator(const ArenaPoolSTLAllocator< U, V > &a)
Constructor from another ArenaPoolSTLAllocator.
const std::string & name() const
ArenaPoolSTLAllocator & operator=(ArenaPoolSTLAllocator &&a)
Move assignment.
void deallocate(pointer, size_type n)
Deallocate objects.
ArenaAllocatorBase::Stats stats() const
std::false_type propagate_on_container_copy_assignment
When we assign to a container, the target should retain its allocator.
Forward declaration.
void maybeUnprotect(ArenaHeapSTLAllocator< T, VETO > &a)
Hook for unprotecting an arena.
STL namespace.
Statistics for an allocator.
Helper to initialize a parameters structure.
Standard STL allocator rebinder.
ArenaPoolSTLAllocator< U, VETO > other
#define private