ATLAS Offline Software
Loading...
Searching...
No Matches
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-2025 CERN for the benefit of the ATLAS collaboration
4*/
57
58
59#ifndef ATLALLOCATORS_ARENASHAREDHEAPSTLALLOCATOR_H
60#define ATLALLOCATORS_ARENASHAREDHEAPSTLALLOCATOR_H
61
62
66#include <string>
67#include <vector>
68
69
70namespace SG {
71
73template <class T>
75
76
90{
91public:
98 ArenaSharedHeapSTLHeader (const void* owner, int nblock);
99
100
107
108
116 void maybe_delete (const void* a);
117
118
123
124
128 template <class T>
129 static std::string get_name();
130
131
135 template <class T>
137
138
146 void update_owner (const void* old_owner, const void* new_owner);
147
148
153 void report (std::ostream& os) const;
154
155
162 void protect();
163
164
171 void unprotect();
172
173
174private:
178 template <class T>
179 static size_t get_index();
180
182 const void* m_owner;
183
185 size_t m_nblock;
186
188 std::vector<ArenaHeapAllocator*> m_allocators;
189};
190
191
192
193
200template <class T>
202{
203public:
206 template <class U> friend class ArenaSharedHeapSTLAllocator;
207
209 typedef T* pointer;
210 typedef const T* const_pointer;
211 typedef T& reference;
212 typedef const T& const_reference;
213 typedef T value_type;
214 typedef size_t size_type;
215 typedef ptrdiff_t difference_type;
216
219
222 typedef std::true_type propagate_on_container_swap;
223
224
226 template <class U> struct rebind {
228 };
229
230
237
238
246
247
250
251
258 template <class U>
260
261
262 // We don't bother to supply a more general constructor --- shouldn't
263 // be needed.
264
265
270
271
281
282
289
290
295
296
304 bool operator== (const ArenaSharedHeapSTLAllocator& other) const;
305
306
314 bool operator!= (const ArenaSharedHeapSTLAllocator& other) const;
315
316
319 template <bool = true>
320 requires (!std::same_as<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 template <bool = true>
339 requires (!std::same_as<reference,const_reference>)
340 void
342 {
343 pointer p_nc ATLAS_THREAD_SAFE = const_cast<pointer>(p);
344 deallocate (p_nc, n);
345 }
346
347
353 size_type max_size() const throw();
354
355
361 template <class... Args>
362 void construct (pointer p, Args&&... args);
363
364
369 void destroy (pointer p);
370
371
375 size_t nblock() const;
376
377
381 const std::string& name() const;
382
383
392 void reset();
393
394
403 void erase();
404
405
423 void reserve (size_t size);
424
425
430
431
437
438
443
444
449
450
455 void report (std::ostream& os) const;
456
457
464 void protect();
465
466
473 void unprotect();
474
475
476private:
479};
480
481
482template <class T>
484{
485 a.swap (b);
486}
487
488
497template <class T>
499
500
501} // namespace SG
502
503
505
506
507#endif // not ATLALLOCATORS_ARENASHAREDHEAPSTLALLOCATOR_H
Registry of allocator factories. See Arena.h for an overview of the arena-based memory allocators.
Heap-based allocator. See Arena.h for an overview of the arena-based memory allocators.
STL-style allocator wrapper for ArenaHeapAllocator.
static Double_t a
#define x
#define ATLAS_THREAD_SAFE
Common base class for arena allocator classes.
Heap-based allocator.
ArenaSharedHeapSTLAllocator(const ArenaSharedHeapSTLAllocator< U > &a)
Constructor from another ArenaSharedHeapSTLAllocator.
void construct(pointer p, Args &&... args)
bool operator!=(const ArenaSharedHeapSTLAllocator &other) const
Inequality test.
std::true_type propagate_on_container_move_assignment
Move allocators on move/swap.
bool operator==(const ArenaSharedHeapSTLAllocator &other) const
Equality test.
void swap(ArenaSharedHeapSTLAllocator &a)
Swap.
std::false_type propagate_on_container_copy_assignment
When we assign to a container, the target should retain its allocator.
void report(std::ostream &os) const
ArenaAllocatorBase::Stats stats() const
T * pointer
Standard STL allocator typedefs.
pointer address(reference x) const
Convert a reference to an address.
size_type max_size() const
Return the maximum number of objects we can allocate at once.
friend class ArenaSharedHeapSTLAllocator
Make all instantiations of this class friends (to be able to copy the header pointer).
~ArenaSharedHeapSTLAllocator()
Destructor.
const std::string & name() const
ArenaSharedHeapSTLAllocator & operator=(const ArenaSharedHeapSTLAllocator &a)
Assignment.
ArenaHeapAllocator * poolptr()
void deallocate(pointer, size_type n)
Deallocate objects.
ArenaSharedHeapSTLAllocator(size_t nblock=1000)
Default constructor.
ArenaSharedHeapSTLAllocator(const ArenaSharedHeapSTLAllocator &a)
Copy constructor.
pointer allocate(size_type n, const void *hint=0)
Allocate new objects.
ArenaSharedHeapSTLAllocator(ArenaSharedHeapSTLAllocator &&a)=default
Move constructor is the same as the copy constructor.
ArenaAllocatorBase::Stats totstats() const
Common header class for ArenaSharedHeapSTLAllocator.
const void * m_owner
Address of the allocator that created this header.
ArenaAllocatorBase::Stats totstats() const
Return allocator statistics summed over all our owned allocators.
void protect()
Write-protect the memory managed by these allocators.
static std::string get_name()
Return the name to use for an allocator for type T.
void update_owner(const void *old_owner, const void *new_owner)
Update the owner of this object.
void unprotect()
Write-enable the memory managed by these allocators.
void report(std::ostream &os) const
Generate printable report for all contained allocators.
size_t m_nblock
Saved value for nblock parameter.
ArenaSharedHeapSTLHeader(const void *owner, int nblock)
Constructor.
void maybe_delete(const void *a)
Call this when an allocator is being deleted.
ArenaHeapAllocator * get_pool()
Return the heap allocator for type T.
std::vector< ArenaHeapAllocator * > m_allocators
List of allocators.
static size_t get_index()
Return the allocator index to use for type T.
STL class.
Forward declaration.
void maybeUnprotect(ArenaHeapSTLAllocator< T, VETO > &a)
Hook for unprotecting an arena.
void swap(ArenaSharedHeapSTLAllocator< T > &a, ArenaSharedHeapSTLAllocator< T > &b)
STL namespace.
Statistics for an allocator.
#define private