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 /include/fud_allocator.hpp | |
parent | 8dcb1de91e15ff7fc66279cd9cd9ad8a70f624e0 (diff) |
Use std::byte* instead of void* for allocators.
Diffstat (limited to 'include/fud_allocator.hpp')
-rw-r--r-- | include/fud_allocator.hpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/include/fud_allocator.hpp b/include/fud_allocator.hpp index d4feccf..e4078ac 100644 --- a/include/fud_allocator.hpp +++ b/include/fud_allocator.hpp @@ -30,9 +30,9 @@ class alignas(std::max_align_t) Allocator { public: virtual ~Allocator() = default; - virtual Result<void*, FudStatus> allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) = 0; + virtual Result<std::byte*, FudStatus> allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) = 0; - virtual FudStatus deallocate(void* pointer, size_t bytes) = 0; + virtual FudStatus deallocate(std::byte* pointer, size_t bytes) = 0; virtual bool isEqual(const Allocator& rhs) const = 0; }; @@ -46,20 +46,33 @@ class FudAllocator : public Allocator { public: virtual ~FudAllocator() override = default; - virtual Result<void*, FudStatus> allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override; + virtual Result<std::byte*, FudStatus> allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override; - virtual FudStatus deallocate(void* pointer, size_t bytes) override; + virtual FudStatus deallocate(std::byte* pointer, size_t bytes) override; virtual bool isEqual(const Allocator& rhs) const override; }; extern FudAllocator globalFudAllocator; +class NullAllocator : public Allocator { + public: + virtual ~NullAllocator() override = default; + + virtual Result<std::byte*, FudStatus> allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override; + + virtual FudStatus deallocate(std::byte* pointer, size_t bytes) override; + + virtual bool isEqual(const Allocator& rhs) const override; +}; + +extern NullAllocator globalNullAllocator; + /** \brief The default allocation function for globalFudAllocator. */ -extern void* fudAlloc(size_t size); +extern std::byte* fudAlloc(size_t size); /** \brief The default deallocation function for globalFudAllocator. */ -extern void fudFree(void* ptr); +extern void fudFree(std::byte* ptr); } // namespace fud |