diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2025-03-30 23:08:43 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2025-03-30 23:08:43 -0500 |
commit | cb9fa588ba8144fcdd52ba4b83d69d93fb18066f (patch) | |
tree | 214574ca68c1551ec76e7fbb9e0263793180231d /include/fud_allocator.hpp | |
parent | 1d357adfa19725ee69fb267a363f1fd217b1272f (diff) |
Add hash map.
Diffstat (limited to 'include/fud_allocator.hpp')
-rw-r--r-- | include/fud_allocator.hpp | 16 |
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 |