summaryrefslogtreecommitdiff
path: root/include/fud_allocator.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2025-03-30 23:08:43 -0500
committerDominick Allen <djallen@librehumanitas.org>2025-03-30 23:08:43 -0500
commitcb9fa588ba8144fcdd52ba4b83d69d93fb18066f (patch)
tree214574ca68c1551ec76e7fbb9e0263793180231d /include/fud_allocator.hpp
parent1d357adfa19725ee69fb267a363f1fd217b1272f (diff)
Add hash map.
Diffstat (limited to 'include/fud_allocator.hpp')
-rw-r--r--include/fud_allocator.hpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/include/fud_allocator.hpp b/include/fud_allocator.hpp
index 99b33ce..8940dcd 100644
--- a/include/fud_allocator.hpp
+++ b/include/fud_allocator.hpp
@@ -79,34 +79,30 @@ extern NullAllocator globalNullAllocator;
template <size_t Size>
class SimpleStackAllocator final : public Allocator {
private:
+ size_t m_allocated{0};
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays)
std::byte m_memory[Size]{};
- size_t m_allocated{0};
public:
~SimpleStackAllocator() final = default;
Result<std::byte*, FudStatus> allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) final
{
- using RetType = Result<std::byte*, FudStatus>;
static_cast<void>(alignment);
- if (bytes > Size - m_allocated) {
- return RetType::error(FudStatus::AllocFailure);
+ if (bytes > (Size - m_allocated)) {
+ return Error{FudStatus::AllocFailure};
}
auto* data = m_memory + m_allocated;
m_allocated += bytes;
- return RetType::okay(data);
+ return Okay{data};
}
void deallocate(std::byte* pointer, size_t bytes) final
{
- if (pointer + bytes != m_memory + m_allocated) {
- m_allocated = Size;
- return;
- }
- m_allocated -= bytes;
+ static_cast<void>(pointer);
+ static_cast<void>(bytes);
}
[[nodiscard]] bool isEqual(const Allocator& rhs) const final