ATLAS Offline Software
Loading...
Searching...
No Matches
ArenaBlock.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-2022 CERN for the benefit of the ATLAS collaboration
4*/
12
13#ifndef ATLALLOCATORS_ARENABLOCK_H
14#define ATLALLOCATORS_ARENABLOCK_H
15
16
17#include <cstdlib>
18#include <atomic>
20
21namespace SG {
22
23
24
26
43{
44public:
46 typedef char* pointer;
47 typedef const char* const_pointer;
48
50 typedef void func_t (pointer);
51
52
64 static ArenaBlock* newBlock (size_t n, size_t elt_size, func_t* ctor);
65
66
72 static void destroy (ArenaBlock* p, func_t* dtor);
73
74
82 static void destroyList (ArenaBlock* p, func_t* dtor);
83
84
94 static void appendList (ArenaBlock** headp, ArenaBlock* tail);
95
96
109 static void applyList (ArenaBlock* p, func_t* func, size_t n);
110
111
115 size_t size() const;
116
117
121 size_t eltSize() const;
122
123
128
129
133 const ArenaBlock* link() const;
134
135
140 pointer index (size_t i);
141
142
147 const_pointer index (size_t i) const;
148
149
159 pointer index (size_t i, size_t elt_size);
160
161
171 const_pointer index (size_t i, size_t elt_size) const;
172
173
180 static size_t overhead();
181
182
184 static size_t nactive();
185
186
193 void protect();
194
195
202 void unprotect();
203
204
212 static void protectList (ArenaBlock* p);
213
214
222 static void unprotectList (ArenaBlock* p);
223
224private:
226 ArenaBlock (size_t n, size_t elt_size);
230
231 // This is not really needed. It's just to squelch the g++ warning
232 // about classes with all private ctors/dtors and no friends.
233 friend class ArenaAllocatorBase;
234
237
239 size_t m_size;
240
243
244 // The start of the block body.
245 // Try to make sure it's aligned.
247
249 static std::atomic<size_t> s_nactive;
250};
251
252
254static const int ArenaBlockBodyOffset =
256
257
258} // namespace SG
259
260
262
263
264#endif // not ATLALLOCATORS_ARENABLOCK_H
A dummy pad struct to put at the end of the ArenaBlock header to ensure the alignment of the elements...
Common base class for arena allocator classes.
A large memory block that gets carved into smaller uniform elements.
Definition ArenaBlock.h:43
static void protectList(ArenaBlock *p)
Write-protect all blocks in a list.
static void destroyList(ArenaBlock *p, func_t *dtor)
Destroy all blocks in a list.
static std::atomic< size_t > s_nactive
Global count of the number of blocks in use.
Definition ArenaBlock.h:249
pointer index(size_t i)
Return a pointer to element i in the block.
void func_t(pointer)
Function that operates on an element.
Definition ArenaBlock.h:50
static void destroy(ArenaBlock *p, func_t *dtor)
Destroy a block.
static ArenaBlock * newBlock(size_t n, size_t elt_size, func_t *ctor)
Create a new block.
ArenaBlock *& link()
Return the link pointer of the block.
char * pointer
Type for a pointer to an element.
Definition ArenaBlock.h:46
const_pointer index(size_t i, size_t elt_size) const
Return a pointer to element i in the block.
ArenaBlock(const ArenaBlock &)
size_t eltSize() const
Return the size of the elements in the block.
static void appendList(ArenaBlock **headp, ArenaBlock *tail)
Concatenate two lists of blocks.
size_t m_elt_size
Size, in bytes, of each element in this block.
Definition ArenaBlock.h:242
const char * const_pointer
Definition ArenaBlock.h:47
const ArenaBlock * link() const
Return the link pointer of the block.
static void unprotectList(ArenaBlock *p)
Write-enable all blocks in a list.
ArenaBlock & operator=(const ArenaBlock &)
ArenaBlock(size_t n, size_t elt_size)
Prohibit calling these.
const_pointer index(size_t i) const
Return a pointer to element i in the block.
size_t m_size
Number of elements in this block.
Definition ArenaBlock.h:239
void unprotect()
Write-enable this block.
pointer index(size_t i, size_t elt_size)
Return a pointer to element i in the block.
size_t size() const
Return the number of elements in the block.
static void applyList(ArenaBlock *p, func_t *func, size_t n)
Call a function on elements in a list of blocks.
ArenaBlockAlignDetail::padForAlign m_dummy
Definition ArenaBlock.h:246
static size_t overhead()
Return the per-block memory overhead, in bytes.
ArenaBlock * m_link
The link for the linked list.
Definition ArenaBlock.h:236
friend class ArenaAllocatorBase
Definition ArenaBlock.h:233
static size_t nactive()
Return the global number of blocks in use.
void protect()
Write-protect this block.
std::string tail(std::string s, const std::string &pattern)
tail of a string
Forward declaration.
static const int ArenaBlockBodyOffset
The offset from the start of the block to the first element.
Definition ArenaBlock.h:254