14class linear_allocator {
19 explicit constexpr linear_allocator(
void* ptr, std::size_t size) noexcept : _ptr(ptr), _head(ptr), _size(size) {
23 linear_allocator(
const linear_allocator&) =
delete;
26 linear_allocator& operator=(
const linear_allocator&) =
delete;
29 linear_allocator(linear_allocator&&) =
default;
32 linear_allocator& operator=(linear_allocator&&) =
default;
38 auto allocate(std::size_t size, std::size_t alignment =
alignof(std::max_align_t))
noexcept ->
void* {
39 assert(
is_power_of_2(alignment) &&
"Alignment must be a power of two");
41 auto space_left = _size - (
static_cast<char*
>(_head) -
static_cast<char*
>(_ptr));
42 auto ptr = std::align(alignment, size, _head, space_left);
46 _head =
static_cast<char*
>(ptr) + size;
51 constexpr void reset() noexcept {
Definition component.hpp:17
constexpr auto is_power_of_2(auto value) -> bool
Check if value is a power of 2.
Definition bits.hpp:17