ATLAS Offline Software
Loading...
Searching...
No Matches
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-2025 CERN for the benefit of the ATLAS collaboration
4*/
39
40
41#ifndef ATLALLOCATORS_ARENAHEAPSTLALLOCATOR
42#define ATLALLOCATORS_ARENAHEAPSTLALLOCATOR
43
44
47#include <string>
48#include <cstddef>
49
50
51namespace SG {
52
53
59template <class T>
61 : public ArenaHeapAllocator::initParams<T, false, true, true>
62{
63public:
66
74 ArenaHeapSTLAllocator_initParams (size_t nblock = 1000,
75 const std::string& name = "");
76
79
81 // Note: gcc 3.2.3 doesn't allow defining this out-of-line.
82 operator ArenaAllocatorBase::Params() const { return params(); }
83};
84
85
92template <class T, class VETO=T>
94{
95public:
97 typedef T* pointer;
98 typedef const T* const_pointer;
99 typedef T& reference;
100 typedef const T& const_reference;
101 typedef T value_type;
102 typedef size_t size_type;
103 typedef ptrdiff_t difference_type;
104
107
110 typedef std::true_type propagate_on_container_swap;
111
112
114 template <class U> struct rebind {
116 };
117
118
126 ArenaHeapSTLAllocator (size_t nblock = 1000, const std::string& name = "");
127
128
135
136
142 template <class U, class V>
144
145
152
153
160
161
166
167
175
176
184 bool operator== (const ArenaHeapSTLAllocator& other) const;
185
186
194 bool operator!= (const ArenaHeapSTLAllocator& other) const;
195
196
197 // We don't bother to supply a more general constructor --- shouldn't
198 // be needed.
199
200
203 template <bool = true>
204 requires (!std::same_as<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 template <bool = true>
223 requires (!std::same_as<reference,const_reference>)
224 void
226 {
227 pointer p_nc ATLAS_THREAD_SAFE = const_cast<pointer>(p);
228 deallocate (p_nc, n);
229 }
230
231
237 size_type max_size() const throw();
238
239
245 template <class... Args>
246 void construct (pointer p, Args&&... args);
247
248
253 void destroy (pointer p);
254
255
259 size_t nblock() const;
260
261
265 const std::string& name() const;
266
267
276 void reset();
277
278
287 void erase();
288
289
307 void reserve (size_t size);
308
309
314
315
320
321
328 void protect();
329
330
337 void unprotect();
338
339
340private:
343};
344
345
346
348template <class T>
350
351
371template <class T>
373 : public std::allocator<T>
374{
375public:
376 typedef std::allocator<T> base;
377
379 typedef typename base::value_type value_type;
380 typedef typename base::size_type size_type;
381 typedef typename base::difference_type difference_type;
382
383
385 template <class U> struct rebind {
387 };
388
389
397 ArenaHeapSTLAllocator (size_t nblock = 1000, const std::string& name = "");
398
399
405 template <class U, class V>
407
408
409 // We don't bother to supply a more general constructor --- shouldn't
410 // be needed.
411
412
416 size_t nblock() const;
417
418
422 const std::string& name() const;
423
424
429
430
435
436
442 template <class CONT>
443 static
445
446
447private:
449 size_t m_nblock;
450
452 std::string m_name;
453
456};
457
458
465template <class T>
467 : public ArenaHeapSTLAllocator<T, T>
468{
469public:
475 template <class U, class V>
477 ArenaBlockAllocatorBase* poolptr_nc);
478
479
488 void reset();
489
490
499 void erase();
500
501
519 void reserve (size_t size);
520
521
528 void protect();
529
530
537 void unprotect();
538
539
540private:
543};
544
545
554template <class T, class VETO>
556
557
558} // namespace SG
559
560
562
563
564#endif // ATLALLOCATORS_ARENAHEAPSTLALLOCATOR
Heap-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.
#define ATLAS_THREAD_SAFE
Common base class for arena allocator classes.
Common functionality for block-oriented allocators.
Heap-based allocator.
base::value_type value_type
Standard STL allocator typedefs.
ArenaAllocatorBase::Stats stats() const
Return the statistics block for this allocator.
const std::string & name() const
Return the name of this allocator.
static ArenaNonConstHeapSTLAllocator< T > get_allocator(CONT &c)
Return an allocator supporting non-const methods from a non-const container reference.
const ArenaBlockAllocatorBase * poolptr() const
Return a pointer to the underlying allocator (may be 0).
const ArenaBlockAllocatorBase * m_poolptr
Point at an underlying allocator from a different specialization.
ArenaHeapSTLAllocator(const ArenaHeapSTLAllocator< U, V > &a)
Constructor from another ArenaHeapSTLAllocator.
ArenaHeapSTLAllocator(size_t nblock=1000, const std::string &name="")
Default constructor.
size_t nblock() const
Return the hinted number of objects allocated per block.
size_t m_nblock
Saved hinted number of objects per block.
std::string m_name
Saved allocator name.
ArenaHeapAllocator::initParams< T, false, true, true > Base
We take defaults from this.
ArenaAllocatorBase::Params params() const
Return an initialized parameters structure.
ArenaHeapSTLAllocator_initParams(size_t nblock=1000, const std::string &name="")
Constructor.
STL-style allocator wrapper for ArenaHeapAllocator.
pointer address(reference x) const
Convert a reference to an address.
bool operator!=(const ArenaHeapSTLAllocator &other) const
Inequality test.
pointer allocate(size_type n, const void *hint=0)
Allocate new objects.
size_type max_size() const
Return the maximum number of objects we can allocate at once.
std::false_type propagate_on_container_copy_assignment
When we assign to a container, the target should retain its allocator.
void construct(pointer p, Args &&... args)
ArenaHeapSTLAllocator(const ArenaHeapSTLAllocator &a)
Copy constructor.
ArenaHeapSTLAllocator & operator=(ArenaHeapSTLAllocator &&a)
Move assignment.
ArenaAllocatorBase::Stats stats() const
T * pointer
Standard STL allocator typedefs.
ArenaHeapSTLAllocator(size_t nblock=1000, const std::string &name="")
Default constructor.
std::true_type propagate_on_container_move_assignment
Move allocators on move/swap.
void deallocate(pointer, size_type n)
Deallocate objects.
const ArenaBlockAllocatorBase * poolptr() const
ArenaHeapSTLAllocator(ArenaHeapSTLAllocator &&a)
Move constructor.
ArenaHeapSTLAllocator select_on_container_copy_construction() const
Return allocator to use for a copy-constructed container.
void swap(ArenaHeapSTLAllocator &a)
Swap.
ArenaHeapSTLAllocator(const ArenaHeapSTLAllocator< U, V > &a)
Constructor from another ArenaHeapSTLAllocator.
bool operator==(const ArenaHeapSTLAllocator &other) const
Equality test.
const std::string & name() const
ArenaNonConstHeapSTLAllocator(const ArenaHeapSTLAllocator< U, V > &a, ArenaBlockAllocatorBase *poolptr_nc)
Constructor.
ArenaBlockAllocatorBase * m_poolptr_nc
Non-const pointer to the underlying allocator.
void protect()
Write-protect the memory managed by this allocator.
void unprotect()
Write-enable the memory managed by this allocator.
void reserve(size_t size)
Set the total number of elements cached by the allocator.
void erase()
Free all allocated elements and release memory back to the system.
void reset()
Free all allocated elements.
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.
ArenaHeapSTLAllocator< U, VETO > other
#define private