nngn
Loading...
Searching...
No Matches
nngn::alloc_block< H, T > Class Template Reference

Non-owning handle to an aggregate header and data block. More...

#include <block.h>

Collaboration diagram for nngn::alloc_block< H, T >:

Classes

struct  storage
 Underlying storage type. More...
 

Public Types

using header_type = H
 
using value_type = T
 
using header_type = H
 
using value_type = T
 

Public Member Functions

 alloc_block (void) noexcept=default
 Initializes a handle with no associated block.
 
constexpr storagedata (void)
 Pointer to the block.
 
constexpr const storagedata (void) const
 Pointer to the block.
 
constexpr header_typeheader (void)
 Pointer to the block header.
 
constexpr const header_typeheader (void) const
 Pointer to the block header.
 
constexpr value_typeget (void)
 Pointer to the data block.
 
constexpr const value_typeget (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.
 
 alloc_block (void) noexcept=default
 Initializes a handle with no associated block.
 
constexpr storagedata (void)
 Pointer to the block.
 
constexpr const storagedata (void) const
 Pointer to the block.
 
constexpr header_typeheader (void)
 Pointer to the block header.
 
constexpr const header_typeheader (void) const
 Pointer to the block header.
 
constexpr value_typeget (void)
 Pointer to the data block.
 
constexpr const value_typeget (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 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.
 
 alloc_block (void *p_)
 Constructs from a pointer to the block.
 

Private Attributes

storagep = nullptr
 Pointer to the underlying storage, non-owning.
 

Static Private Attributes

static constexpr bool both_trivial = trivial<H> && trivial<T>
 

Detailed Description

template<typename H, typename T = char>
class nngn::alloc_block< H, 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).

Template Parameters
HThe type stored in the header region.
TThe 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.

Member Typedef Documentation

◆ header_type [1/2]

template<typename H , typename T = char>
using nngn::alloc_block< H, T >::header_type = H

◆ header_type [2/2]

template<typename H , typename T = char>
using nngn::alloc_block< H, T >::header_type = H

◆ value_type [1/2]

template<typename H , typename T = char>
using nngn::alloc_block< H, T >::value_type = T

◆ value_type [2/2]

template<typename H , typename T = char>
using nngn::alloc_block< H, T >::value_type = T

Constructor & Destructor Documentation

◆ alloc_block() [1/4]

template<typename H , typename T = char>
nngn::alloc_block< H, T >::alloc_block ( void  )
defaultnoexcept

Initializes a handle with no associated block.

◆ alloc_block() [2/4]

template<typename H , typename T = char>
nngn::alloc_block< H, T >::alloc_block ( void *  p_)
inlineexplicitprivate

Constructs from a pointer to the block.

◆ alloc_block() [3/4]

template<typename H , typename T = char>
nngn::alloc_block< H, T >::alloc_block ( void  )
defaultnoexcept

Initializes a handle with no associated block.

◆ alloc_block() [4/4]

template<typename H , typename T = char>
nngn::alloc_block< H, T >::alloc_block ( void *  p_)
inlineexplicitprivate

Constructs from a pointer to the block.

Member Function Documentation

◆ alloc() [1/4]

template<typename H , typename T = char>
static alloc_block nngn::alloc_block< H, T >::alloc ( std::size_t  s)
inlinestatic

Allocates a block to contain s bytes of data.

Here is the call graph for this function:

◆ alloc() [2/4]

template<typename H , typename T = char>
static alloc_block nngn::alloc_block< H, T >::alloc ( std::size_t  s)
inlinestatic

Allocates a block to contain s bytes of data.

Here is the call graph for this function:

◆ alloc() [3/4]

template<typename H , typename T = char>
static alloc_block nngn::alloc_block< H, T >::alloc ( void  )
inlinestatic

Allocates a block to contain exactly a T.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ alloc() [4/4]

template<typename H , typename T = char>
static alloc_block nngn::alloc_block< H, T >::alloc ( void  )
inlinestatic

Allocates a block to contain exactly a T.

Here is the call graph for this function:

◆ alloc_size() [1/2]

template<typename H , typename T >
constexpr std::size_t nngn::alloc_block< H, T >::alloc_size ( std::size_t  n)
inlinestaticconstexpr

Total size of an allocation for n elements.

◆ alloc_size() [2/2]

template<typename H , typename T = char>
static constexpr std::size_t nngn::alloc_block< H, T >::alloc_size ( std::size_t  n)
staticconstexpr

Total size of an allocation for n elements.

◆ data() [1/4]

template<typename H , typename T = char>
constexpr storage * nngn::alloc_block< H, T >::data ( void  )
inlineconstexpr

Pointer to the block.

Here is the caller graph for this function:

◆ data() [2/4]

template<typename H , typename T = char>
constexpr storage * nngn::alloc_block< H, T >::data ( void  )
inlineconstexpr

Pointer to the block.

◆ data() [3/4]

template<typename H , typename T = char>
constexpr const storage * nngn::alloc_block< H, T >::data ( void  ) const
inlineconstexpr

Pointer to the block.

◆ data() [4/4]

template<typename H , typename T = char>
constexpr const storage * nngn::alloc_block< H, T >::data ( void  ) const
inlineconstexpr

Pointer to the block.

◆ free() [1/2]

template<typename H , typename T = char>
void nngn::alloc_block< H, T >::free ( void  )
inline

Frees the block's memory.

Must be called explicitly.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free() [2/2]

template<typename H , typename T = char>
void nngn::alloc_block< H, T >::free ( void  )
inline

Frees the block's memory.

Must be called explicitly.

Here is the call graph for this function:

◆ from_ptr() [1/2]

template<typename H , typename T >
constexpr auto nngn::alloc_block< H, T >::from_ptr ( T p)
inlinestaticconstexpr

Offsets p to the beginning of the entire block.

◆ from_ptr() [2/2]

template<typename H , typename T = char>
static constexpr alloc_block nngn::alloc_block< H, T >::from_ptr ( T p)
staticconstexpr

Offsets p to the beginning of the entire block.

◆ from_storage_ptr() [1/2]

template<typename H , typename T = char>
static constexpr auto nngn::alloc_block< H, T >::from_storage_ptr ( void *  p)
inlinestaticconstexpr

Constructs a handle to a pre-existing storage block.

◆ from_storage_ptr() [2/2]

template<typename H , typename T = char>
static constexpr auto nngn::alloc_block< H, T >::from_storage_ptr ( void *  p)
inlinestaticconstexpr

Constructs a handle to a pre-existing storage block.

◆ get() [1/4]

template<typename H , typename T = char>
constexpr value_type * nngn::alloc_block< H, T >::get ( void  )
inlineconstexpr

Pointer to the data block.

◆ get() [2/4]

template<typename H , typename T = char>
constexpr value_type * nngn::alloc_block< H, T >::get ( void  )
inlineconstexpr

Pointer to the data block.

◆ get() [3/4]

template<typename H , typename T = char>
constexpr const value_type * nngn::alloc_block< H, T >::get ( void  ) const
inlineconstexpr

Pointer to the data block.

◆ get() [4/4]

template<typename H , typename T = char>
constexpr const value_type * nngn::alloc_block< H, T >::get ( void  ) const
inlineconstexpr

Pointer to the data block.

◆ header() [1/4]

template<typename H , typename T = char>
constexpr header_type * nngn::alloc_block< H, T >::header ( void  )
inlineconstexpr

Pointer to the block header.

◆ header() [2/4]

template<typename H , typename T = char>
constexpr header_type * nngn::alloc_block< H, T >::header ( void  )
inlineconstexpr

Pointer to the block header.

◆ header() [3/4]

template<typename H , typename T = char>
constexpr const header_type * nngn::alloc_block< H, T >::header ( void  ) const
inlineconstexpr

Pointer to the block header.

◆ header() [4/4]

template<typename H , typename T = char>
constexpr const header_type * nngn::alloc_block< H, T >::header ( void  ) const
inlineconstexpr

Pointer to the block header.

◆ realloc() [1/2]

template<typename H , typename T = char>
void nngn::alloc_block< H, T >::realloc ( std::size_t  s)
inline

Reallocates the entire block.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ realloc() [2/2]

template<typename H , typename T = char>
void nngn::alloc_block< H, T >::realloc ( std::size_t  s)
inline

Reallocates the entire block.

Here is the call graph for this function:

Member Data Documentation

◆ both_trivial

template<typename H , typename T = char>
static constexpr bool nngn::alloc_block< H, T >::both_trivial = trivial<H> && trivial<T>
staticconstexprprivate

◆ data_offset

template<typename H , typename T = char>
static constexpr std::size_t nngn::alloc_block< H, T >::data_offset
staticconstexpr
Initial value:
= [] {
if constexpr(std::is_standard_layout_v<alloc_block::storage>)
return offsetof(alloc_block::storage, data);
else {
struct S {
alignas(header_type) char header[sizeof(header_type)];
alignas(value_type) char data[sizeof(value_type)];
};
return offsetof(S, data);
}
}()
constexpr storage * data(void)
Pointer to the block.
Definition: block.h:68
data
Definition: house0.lua:10
#define S(v0, v1)
Definition: vec2.h:16

Total size of an allocation for n elements.

◆ p

template<typename H , typename T = char>
storage * nngn::alloc_block< H, T >::p = nullptr
private

Pointer to the underlying storage, non-owning.


The documentation for this class was generated from the following files: