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. --- include/fud_allocator.hpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'include/fud_allocator.hpp') 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 allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) = 0; + virtual Result 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 allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) override; + virtual Result 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 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 -- cgit v1.2.3