From 6c7fd1db481ff10a16ecab958c6542784fa60b9c Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Wed, 30 Oct 2024 09:51:54 -0500 Subject: Use std::byte* instead of void* for allocators. --- source/fud_allocator.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'source/fud_allocator.cpp') 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 FudAllocator::allocate(size_t bytes, size_t alignment) +Result FudAllocator::allocate(size_t bytes, size_t alignment) { - using RetType = Result; + using RetType = Result; static_cast(alignment); - auto* pointer = static_cast(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 NullAllocator::allocate(size_t bytes, size_t alignment) +{ + static_cast(bytes); + static_cast(alignment); + return FudError{FudStatus::Failure}; +} + +FudStatus NullAllocator::deallocate(std::byte* pointer, size_t bytes) +{ + static_cast(pointer); + static_cast(bytes); + return FudStatus::Failure; +} + +bool NullAllocator::isEqual(const Allocator& rhs) const +{ + return &rhs == static_cast(this); +} + +NullAllocator globalNullAllocator{}; + } // namespace fud -- cgit v1.2.3