29#include <EASTL/utility.h>
55template <
size_t N, Safe safety = Safe::Yes>
64 uint8_t *
ptr = m_current;
68 template <
typename T,
typename... Args>
72 size_t size = (
sizeof(T) + 3) & ~size_t(3);
73 uint8_t *
ptr = m_current;
74 if constexpr (
alignof(T) > 1) {
75 static constexpr size_t a =
alignof(T) - 1;
76 auto alignedptr =
reinterpret_cast<uint8_t *
>((
reinterpret_cast<uintptr_t
>(
ptr) + a) & ~a);
84 return *
new (
ptr) T(eastl::forward<Args>(args)...);
86 void reset() { m_current = m_memory; }
87 size_t remaining()
const {
return N - (m_current - m_memory); }
88 size_t used()
const {
return m_current - m_memory; }
91 uint8_t m_memory[
N] __attribute__((aligned(4)));
92 uint8_t *m_current = m_memory;
102template <Safe safety = Safe::Yes>
106 : m_memory(reinterpret_cast<uint8_t *>(storage)), m_current(m_memory), m_size(
size) {
109 "DynamicBumpAllocator: storage must be non-null and 4-byte aligned");
119 uint8_t *
ptr = m_current;
124 template <
typename T,
typename... Args>
128 size_t size = (
sizeof(T) + 3) & ~size_t(3);
129 uint8_t *
ptr = m_current;
130 if constexpr (
alignof(T) > 1) {
131 static constexpr size_t a =
alignof(T) - 1;
132 auto alignedptr =
reinterpret_cast<uint8_t *
>((
reinterpret_cast<uintptr_t
>(
ptr) + a) & ~a);
140 return *
new (
ptr) T(eastl::forward<Args>(args)...);
143 void reset() { m_current = m_memory; }
144 size_t remaining()
const {
return m_size - (m_current - m_memory); }
145 size_t used()
const {
return m_current - m_memory; }
A bump allocator for fragments.
Definition bump-allocator.hh:56
size_t remaining() const
Definition bump-allocator.hh:87
Fragments::SimpleFragment< P > & allocateFragment(Args &&...args)
Definition bump-allocator.hh:59
T & allocate(Args &&...args)
Definition bump-allocator.hh:69
size_t used() const
Definition bump-allocator.hh:88
void reset()
Definition bump-allocator.hh:86
A bump allocator whose capacity is chosen at runtime.
Definition bump-allocator.hh:103
T & allocate(Args &&...args)
Definition bump-allocator.hh:125
void reset()
Definition bump-allocator.hh:143
Fragments::SimpleFragment< P > & allocateFragment(Args &&...args)
Definition bump-allocator.hh:114
size_t used() const
Definition bump-allocator.hh:145
size_t capacity() const
Definition bump-allocator.hh:146
DynamicBumpAllocator(void *storage, size_t size)
Definition bump-allocator.hh:105
size_t remaining() const
Definition bump-allocator.hh:144
static int size
Definition string.h:149
The Primitive concept.
Definition primitive-concept.hh:38
volatile uint32_t * ptr
Definition cop0.c:80
#define N
Definition main.c:37
void assert(bool condition, const char *message, std::source_location location=std::source_location::current())
A simple assert macro.
Definition kernel.hh:366
Definition fragments.hh:95