2#ifndef LIBSBX_MEMORY_MONOTONIC_ARENA_HPP_
3#define LIBSBX_MEMORY_MONOTONIC_ARENA_HPP_
11 using pointer = std::uint8_t*;
18 auto allocate(std::size_t count, std::size_t align) -> pointer {
19 const auto current =
reinterpret_cast<std::size_t
>(_buffer + _offset);
20 const auto aligned = (current + align - 1) & ~(align - 1);
21 const auto new_offset = aligned -
reinterpret_cast<std::size_t
>(_buffer) + count;
23 if (new_offset > _size) {
24 throw std::bad_alloc{};
29 return reinterpret_cast<std::uint8_t*
>(aligned);
40template<
typename Type, std::
size_t Size>
43 template<
typename T, std::
size_t S>
48 using value_type = Type;
49 using pointer = value_type*;
51 template<
typename Other>
58 _arena(_buffer.data(), _buffer.size()) { }
60 template<
typename Other>
61 monotonic_arena_allocator(
const monotonic_arena_allocator<Other, Size>& other) noexcept
62 : _buffer{other._buffer},
63 _arena(other._arena) {}
65 auto allocate(std::size_t count) -> pointer {
66 return static_cast<pointer
>(_arena.allocate(
sizeof(value_type) * count,
alignof(value_type)));
69 auto deallocate(pointer, std::size_t)
noexcept ->
void {
75 std::span<std::uint8_t, Size> _buffer;
76 monotonic_arena _arena;
80template<
typename Key,
typename Value, std::
size_t Size>
81using monotonic_arena_map_allocator = monotonic_arena_allocator<std::pair<const Key, Value>, Size>;
Definition: monotonic_arena.hpp:41
Definition: monotonic_arena.hpp:7
Definition: monotonic_arena.hpp:52