nngn
|
Non-owning handle to an aggregate header and data block. More...
#include <block.h>
Classes | |
struct | storage |
Underlying storage type. More... | |
Public Types | |
using | header_type = H |
using | value_type = T |
Public Member Functions | |
alloc_block (void) noexcept=default | |
Initializes a handle with no associated block. | |
constexpr storage * | data (void) |
Pointer to the block. | |
constexpr const storage * | data (void) const |
Pointer to the block. | |
constexpr header_type * | header (void) |
Pointer to the block header. | |
constexpr const header_type * | header (void) const |
Pointer to the block header. | |
constexpr value_type * | get (void) |
Pointer to the data block. | |
constexpr const value_type * | get (void) const |
Pointer to the data block. | |
void | realloc (std::size_t s) |
Reallocates the entire block. | |
void | free (void) |
Frees the block's memory. | |
Static Public Member Functions | |
static constexpr std::size_t | alloc_size (std::size_t n) |
Total size of an allocation for n elements. | |
static constexpr auto | from_storage_ptr (void *p) |
Constructs a handle to a pre-existing storage block. | |
static constexpr alloc_block | from_ptr (T *p) |
Offsets p to the beginning of the entire block. | |
static alloc_block | alloc (void) |
Allocates a block to contain exactly a T . | |
static alloc_block | alloc (std::size_t s) |
Allocates a block to contain s bytes of data. | |
Static Public Attributes | |
static constexpr std::size_t | data_offset |
Total size of an allocation for n elements. | |
Private Member Functions | |
alloc_block (void *p_) | |
Constructs from a pointer to the block. | |
Private Attributes | |
storage * | p = nullptr |
Pointer to the underlying storage, non-owning. | |
Static Private Attributes | |
static constexpr bool | both_trivial = trivial<H> && trivial<T> |
Non-owning handle to an aggregate header and data block.
Primarily (but not necessarily) intended to be used in allocators. The underlying object is allocated as one block of memory. The handle provides accessors to both the header and data regions, as well as methods to reallocate and free the block.
Allocation functions are available if both types are trivial (since malloc
, realloc
, and free
are used).
H | The type stored in the header region. |
T | The type stored in the data region. The default is char , which can either be a single byte or (more likely) used with alloc(size) to allocate a block of bytes. data() will the point to the beginning of the block. |
using nngn::alloc_block< H, T >::header_type = H |
using nngn::alloc_block< H, T >::value_type = T |
|
defaultnoexcept |
Initializes a handle with no associated block.
|
inlineexplicitprivate |
Constructs from a pointer to the block.
|
inlinestatic |
Allocates a block to contain s
bytes of data.
|
inlinestatic |
Allocates a block to contain exactly a T
.
|
inlinestaticconstexpr |
Total size of an allocation for n
elements.
|
inlineconstexpr |
Pointer to the block.
|
inlineconstexpr |
Pointer to the block.
|
inline |
Frees the block's memory.
Must be called explicitly.
|
inlinestaticconstexpr |
Offsets p
to the beginning of the entire block.
|
inlinestaticconstexpr |
Constructs a handle to a pre-existing storage block.
|
inlineconstexpr |
Pointer to the data block.
|
inlineconstexpr |
Pointer to the data block.
|
inlineconstexpr |
Pointer to the block header.
|
inlineconstexpr |
Pointer to the block header.
|
inline |
Reallocates the entire block.
|
staticconstexprprivate |
|
staticconstexpr |
|
private |
Pointer to the underlying storage, non-owning.