summaryrefslogtreecommitdiff
path: root/source/fud_allocator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/fud_allocator.cpp')
-rw-r--r--source/fud_allocator.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/source/fud_allocator.cpp b/source/fud_allocator.cpp
index 8daf969..d5127fa 100644
--- a/source/fud_allocator.cpp
+++ b/source/fud_allocator.cpp
@@ -19,18 +19,18 @@
namespace fud {
-Result<void*, FudStatus> FudAllocator::allocate(size_t bytes, size_t alignment)
+Result<std::byte*, FudStatus> FudAllocator::allocate(size_t bytes, size_t alignment)
{
- using RetType = Result<void*, FudStatus>;
+ using RetType = Result<std::byte*, FudStatus>;
static_cast<void>(alignment);
- auto* pointer = static_cast<std::byte*>(fudAlloc(bytes));
+ auto* pointer = fudAlloc(bytes);
if (pointer == nullptr) {
return RetType::error(FudStatus::AllocFailure);
}
return RetType::okay(pointer);
}
-FudStatus FudAllocator::deallocate(void* pointer, size_t bytes)
+FudStatus FudAllocator::deallocate(std::byte* pointer, size_t bytes)
{
if (pointer == nullptr || bytes == 0) {
return FudStatus::ArgumentInvalid;
@@ -46,4 +46,25 @@ bool FudAllocator::isEqual(const Allocator& rhs) const
FudAllocator globalFudAllocator{};
+Result<std::byte*, FudStatus> NullAllocator::allocate(size_t bytes, size_t alignment)
+{
+ static_cast<void>(bytes);
+ static_cast<void>(alignment);
+ return FudError{FudStatus::Failure};
+}
+
+FudStatus NullAllocator::deallocate(std::byte* pointer, size_t bytes)
+{
+ static_cast<void>(pointer);
+ static_cast<void>(bytes);
+ return FudStatus::Failure;
+}
+
+bool NullAllocator::isEqual(const Allocator& rhs) const
+{
+ return &rhs == static_cast<const Allocator*>(this);
+}
+
+NullAllocator globalNullAllocator{};
+
} // namespace fud