ATLAS Offline Software
|
A large memory block that gets carved into smaller uniform elements. More...
#include <ArenaBlock.h>
Public Types | |
typedef char * | pointer |
Type for a pointer to an element. More... | |
typedef const char * | const_pointer |
typedef void | func_t(pointer) |
Function that operates on an element. More... | |
Public Member Functions | |
size_t | size () const |
Return the number of elements in the block. More... | |
size_t | eltSize () const |
Return the size of the elements in the block. More... | |
ArenaBlock *& | link () |
Return the link pointer of the block. More... | |
const ArenaBlock * | link () const |
Return the link pointer of the block. More... | |
pointer | index (size_t i) |
Return a pointer to element i in the block. More... | |
const_pointer | index (size_t i) const |
Return a pointer to element i in the block. More... | |
pointer | index (size_t i, size_t elt_size) |
Return a pointer to element i in the block. More... | |
const_pointer | index (size_t i, size_t elt_size) const |
Return a pointer to element i in the block. More... | |
void | protect () |
Write-protect this block. More... | |
void | unprotect () |
Write-enable this block. More... | |
Static Public Member Functions | |
static ArenaBlock * | newBlock (size_t n, size_t elt_size, func_t *ctor) |
Create a new block. More... | |
static void | destroy (ArenaBlock *p, func_t *dtor) |
Destroy a block. More... | |
static void | destroyList (ArenaBlock *p, func_t *dtor) |
Destroy all blocks in a list. More... | |
static void | appendList (ArenaBlock **headp, ArenaBlock *tail) |
Concatenate two lists of blocks. More... | |
static void | applyList (ArenaBlock *p, func_t *func, size_t n) |
Call a function on elements in a list of blocks. More... | |
static size_t | overhead () |
Return the per-block memory overhead, in bytes. More... | |
static size_t | nactive () |
Return the global number of blocks in use. More... | |
static void | protectList (ArenaBlock *p) |
Write-protect all blocks in a list. More... | |
static void | unprotectList (ArenaBlock *p) |
Write-enable all blocks in a list. More... | |
Private Member Functions | |
ArenaBlock (size_t n, size_t elt_size) | |
Prohibit calling these. More... | |
~ArenaBlock () | |
ArenaBlock (const ArenaBlock &) | |
ArenaBlock & | operator= (const ArenaBlock &) |
Private Attributes | |
ArenaBlock * | m_link |
The link for the linked list. More... | |
size_t | m_size |
Number of elements in this block. More... | |
size_t | m_elt_size |
Size, in bytes, of each element in this block. More... | |
ArenaBlockAlignDetail::padForAlign | m_dummy |
Static Private Attributes | |
static std::atomic< size_t > | s_nactive |
Global count of the number of blocks in use. More... | |
Friends | |
class | ArenaAllocatorBase |
A large memory block that gets carved into smaller uniform elements.
See Arena.h for an overview of the arena-based memory allocators.
The block-based memory allocators allocate memory in large blocks and then carve them up into smaller, uniform elements. This class is used for those large blocks. Actually, the contents of this class is a fixed header for the block; the contents of the block itself will immediately follow the class contents.
Each block keeps some housekeeping information: the element size in bytes, the number of elements in the block, and a pointer that can be used to chain blocks together in singly-linked lists. There are a few functions available to help manage such lists.
Definition at line 42 of file ArenaBlock.h.
typedef const char* SG::ArenaBlock::const_pointer |
Definition at line 47 of file ArenaBlock.h.
typedef void SG::ArenaBlock::func_t(pointer) |
Function that operates on an element.
Definition at line 50 of file ArenaBlock.h.
typedef char* SG::ArenaBlock::pointer |
Type for a pointer to an element.
Definition at line 46 of file ArenaBlock.h.
|
private |
Prohibit calling these.
|
inlineprivate |
Definition at line 227 of file ArenaBlock.h.
|
private |
|
static |
Concatenate two lists of blocks.
headp | Pointer to pointer to the head of the list. |
tail | Pointer to list to append to the end. |
The list tail
is appended to the end of the list *headp
. (headp
is a pointer-to-pointer to be able to handle the case of an empty list.)
Definition at line 110 of file ArenaBlock.cxx.
|
static |
Call a function on elements in a list of blocks.
p | Pointer to the head of the list. |
func | Function to apply. |
n | Number of elements in the first block on which to call the function. |
This will loop through the elements in all blocks on the list, calling func
. In the first block, we apply the function only to the first n
elements. In subsequent blocks, the function is applied to all elements.
p | Pointer to the head of the list. |
func | Function to apply. |
Number | of elements in the first block on which to call the function. |
This will loop through the elements in all blocks on the list, calling func
. In the first block, we apply the function only to the first n
elements. In subsequent blocks, the function is applied to all elements.
Definition at line 131 of file ArenaBlock.cxx.
|
static |
Destroy a block.
p | The block to destroy. |
dtor | If non-null, call this function on each element in the block. |
Definition at line 69 of file ArenaBlock.cxx.
|
static |
Destroy all blocks in a list.
p | The first block to destroy. |
dtor | If non-null, call this function on each element in the blocks. |
Will destroy all blocks in the linked list headed by p
.
p | The first block to destroy. |
dtor | If non-null, call this function on each element the blocks. |
Will destroy all blocks in the linked list headed by p
.
Definition at line 91 of file ArenaBlock.cxx.
size_t SG::ArenaBlock::eltSize | ( | ) | const |
Return the size of the elements in the block.
pointer SG::ArenaBlock::index | ( | size_t | i | ) |
Return a pointer to element i
in the block.
i | The index of the desired element. |
const_pointer SG::ArenaBlock::index | ( | size_t | i | ) | const |
Return a pointer to element i
in the block.
i | The index of the desired element. |
pointer SG::ArenaBlock::index | ( | size_t | i, |
size_t | elt_size | ||
) |
Return a pointer to element i
in the block.
i | The index of the desired element. |
elt_size | The block's element size. |
This is provided in addition to the previous function as it may allow for better inlined code in when used in a loop, if elt_size
is saved in a local.
const_pointer SG::ArenaBlock::index | ( | size_t | i, |
size_t | elt_size | ||
) | const |
Return a pointer to element i
in the block.
i | The index of the desired element. |
elt_size | The block's element size. |
This is provided in addition to the previous function as it may allow for better inlined code in when used in a loop, if elt_size
is saved in a local.
ArenaBlock* & SG::ArenaBlock::link | ( | ) |
Return the link pointer of the block.
const ArenaBlock* SG::ArenaBlock::link | ( | ) | const |
Return the link pointer of the block.
|
static |
Return the global number of blocks in use.
|
static |
Create a new block.
n | The number of elements in the new block. |
elt_size | The size in bytes of each element. |
ctor | If non-null, call this function on each element in the new block. |
The block will be allocated so that it entirely occupies a set of contiguous pages. The requested size may be rounded up for this.
Definition at line 41 of file ArenaBlock.cxx.
|
private |
|
static |
Return the per-block memory overhead, in bytes.
This tries to include malloc overhead as well, but that may just be an estimate. Don't rely on this to be exact.
Definition at line 157 of file ArenaBlock.cxx.
void SG::ArenaBlock::protect | ( | ) |
Write-protect this block.
Adjust protection on the memory allocated for this block to disallow writes.
Definition at line 170 of file ArenaBlock.cxx.
|
static |
size_t SG::ArenaBlock::size | ( | ) | const |
Return the number of elements in the block.
void SG::ArenaBlock::unprotect | ( | ) |
Write-enable this block.
Adjust protection on the memory allocated for this block to allow writes.
Definition at line 186 of file ArenaBlock.cxx.
|
static |
|
friend |
Definition at line 233 of file ArenaBlock.h.
|
private |
Definition at line 246 of file ArenaBlock.h.
|
private |
Size, in bytes, of each element in this block.
Definition at line 242 of file ArenaBlock.h.
|
private |
The link for the linked list.
Definition at line 236 of file ArenaBlock.h.
|
private |
Number of elements in this block.
Definition at line 239 of file ArenaBlock.h.
|
staticprivate |
Global count of the number of blocks in use.
Global number of blocks in use.
Definition at line 249 of file ArenaBlock.h.