diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-10-30 09:51:54 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-10-30 09:51:54 -0500 |
commit | 6c7fd1db481ff10a16ecab958c6542784fa60b9c (patch) | |
tree | e0162f930ec44a7c53b07061311d52910c36e481 /source/fud_allocator.cpp | |
parent | 8dcb1de91e15ff7fc66279cd9cd9ad8a70f624e0 (diff) |
Use std::byte* instead of void* for allocators.
Diffstat (limited to 'source/fud_allocator.cpp')
-rw-r--r-- | source/fud_allocator.cpp | 29 |
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 |