#include <buffer.h>
Public Member Functions | |
ByteSpan | as_bytes () |
std::byte * | data () |
size_t | size () const |
T & | operator* () |
const T & | operator* () const |
T * | operator-> () |
const T * | operator-> () const |
Static Public Attributes | |
static constexpr size_t | kCapacity = kBufferSize |
Associates a default-constructed type with a memory buffer.
Although the type is arbitrary, the intended purpose of of this class is to provide allocators with memory to use, e.g. when testing.
This class uses composition instead of inheritance in order to allow the wrapped type's destructor to reference the memory without risk of a use-after-free. As a result, the specific methods of the wrapped type are not directly accesible. Instead, they can be accessed using the *
and ->
operators, e.g.
Note that this class does NOT initialize the allocator, since initialization is not specified as part of the Allocator
interface and may vary from allocator to allocator. As a result, typical usage includes deriving a class that initializes the wrapped allocator with the buffer in a constructor. See AllocatorForTest
for an example.
T | The wrapped object. |
kBufferSize | The size of the backing memory, in bytes. |
kAlignment | Buffer memory will be aligned to this alignment boundary. |