Simple internal arena block of memory. Maintains the underlying memory.
More...
#include <MemArena.h>
|
| static constexpr size_t | MIN_FREE_SPACE = 16 |
| | A block must have at least this much free space to not be "full".
|
| |
|
| | Block (size_t n) noexcept |
| |
Simple internal arena block of memory. Maintains the underlying memory.
Definition at line 60 of file MemArena.h.
◆ Block()
| swoc::MemArena::Block::Block |
( |
size_t | n | ) |
|
|
explicitprotectednoexcept |
Construct to have n bytes of available storage.
Note this is descriptive - this presumes use via placement new and the size value describes memory already allocated immediately after this instance.
- Parameters
-
◆ align_padding()
| static size_t swoc::MemArena::Block::align_padding |
( |
void const * | ptr, |
|
|
size_t | align ) |
|
static |
Compute the padding needed such adding it to ptr is a multiple of align.
- Parameters
-
| ptr | Base pointer. |
| align | Alignment requirement (must be a power of 2). |
- Returns
- Value to add to ptr to achieve align.
◆ alloc()
Allocate n bytes from this block.
- Parameters
-
| n | Number of bytes to allocate. |
| align | Alignment requirement (default, no alignment). |
- Returns
- The span of memory allocated.
◆ allocated_data_end() [1/2]
| char * swoc::MemArena::Block::allocated_data_end |
( |
| ) |
|
- Returns
- The first byte past allocated storage.
◆ allocated_data_end() [2/2]
| const char * swoc::MemArena::Block::allocated_data_end |
( |
| ) |
const |
- Returns
- The first byte past allocated storage.
◆ contains()
| bool swoc::MemArena::Block::contains |
( |
const void * | ptr | ) |
const |
Check if the byte at address ptr is in this block.
- Parameters
-
| ptr | Address of byte to check. |
- Returns
true if ptr is in this block, false otherwise.
◆ discard()
| Block & swoc::MemArena::Block::discard |
( |
| ) |
|
Discard allocations.
Reset the block state to empty.
- Returns
- this.
◆ is_full()
| bool swoc::MemArena::Block::is_full |
( |
| ) |
const |
- Returns
true if the block has at least MIN_FREE_SPACE bytes free.
◆ operator delete() [1/2]
| static void swoc::MemArena::Block::operator delete |
( |
void * | ptr | ) |
|
|
staticprotectednoexcept |
Override operator delete.
This is required because the allocated memory size is larger than the class size which requires calling free directly, skipping the destructor and avoiding complaints about size mismatches.
- Parameters
-
| ptr | Memory to be de-allocated. |
◆ operator delete() [2/2]
| static void swoc::MemArena::Block::operator delete |
( |
void * | ptr, |
|
|
void * | place ) |
|
staticprotectednoexcept |
Override placement (non-allocated) delete.
- Parameters
-
| ptr | Pointer returned from new |
| place | Value passed to new. |
This is called only when the class constructor throws an exception during placement new.
- Note
- I think the parameters are described correctly, the documentation I can find is a bit vague on the source of these values. It is required even if the constructor is marked
noexcept. Both are kept in order to be documented.
◆ satisfies()
| bool swoc::MemArena::Block::satisfies |
( |
size_t | n, |
|
|
size_t | align ) const |
|
inline |
Check if there is n bytes of space at align.
- Parameters
-
| n | Size required. |
| align | Alignment required. |
- Returns
true if there is space, false if not.
Definition at line 16 of file MemArena.cc.
◆ allocated
| size_t swoc::MemArena::Block::allocated {0} |
|
protected |
Current allocated (in use) bytes.
Definition at line 163 of file MemArena.h.
◆ MemArena
| friend swoc::MemArena::Block::MemArena |
|
protected |
◆ MIN_FREE_SPACE
| size_t swoc::MemArena::Block::MIN_FREE_SPACE = 16 |
|
staticconstexpr |
A block must have at least this much free space to not be "full".
Definition at line 62 of file MemArena.h.
◆ size
| size_t swoc::MemArena::Block::size |
|
protected |
The documentation for this struct was generated from the following files: