diff --git a/Source/Config.cpp b/Source/Config.cpp index 51deb6fb5f6..0a67db7c816 100644 --- a/Source/Config.cpp +++ b/Source/Config.cpp @@ -8,7 +8,7 @@ #include -#if IS_WIN32() +#if IS_WIN32() || IS_WIN64() #include #include #include diff --git a/Source/MemoryAllocation/MemoryAllocator.h b/Source/MemoryAllocation/MemoryAllocator.h index e8b66903534..7c3db5bdd04 100644 --- a/Source/MemoryAllocation/MemoryAllocator.h +++ b/Source/MemoryAllocation/MemoryAllocator.h @@ -8,23 +8,60 @@ #include "FreeMemoryRegionList.h" struct MemoryAllocator { - [[nodiscard]] static std::byte* allocate(std::size_t size) noexcept; - static void deallocate(std::byte* memory, std::size_t size) noexcept; - template + requires (!std::is_array_v) + [[nodiscard]] static std::byte* allocate() noexcept + { + return allocate(memoryFor()); + } + + template + requires std::is_unbounded_array_v + [[nodiscard]] static std::byte* allocate(std::size_t numberOfElements) noexcept + { + return allocate(memoryFor(numberOfElements)); + } + + template + requires std::is_bounded_array_v + static void allocate(Args&&...) = delete; + + template + requires (!std::is_array_v) + static void deallocate(T* memory) noexcept + { + deallocate(reinterpret_cast(memory), memoryFor()); + } + + template + requires std::is_unbounded_array_v + static void deallocate(std::remove_extent_t* memory, std::size_t numberOfElements) noexcept + { + deallocate(reinterpret_cast(memory), memoryFor(numberOfElements)); + } + + template + requires std::is_bounded_array_v + static void deallocate(Args&&...) = delete; + +private: + template + requires (!std::is_array_v) [[nodiscard]] static auto memoryFor() noexcept { - static_assert(!std::is_array_v); static_assert(alignof(T) <= FreeMemoryRegionList::minimumAlignment(), "Unsupported alignment"); return utils::align(); } template + requires std::is_unbounded_array_v [[nodiscard]] static auto memoryFor(std::size_t numberOfElements) noexcept { - static_assert(std::is_array_v); static_assert(alignof(T) <= FreeMemoryRegionList::minimumAlignment(), "Unsupported alignment"); assert(numberOfElements <= (std::numeric_limits::max)() / sizeof(std::remove_extent_t)); return utils::align(numberOfElements * sizeof(std::remove_extent_t), FreeMemoryRegionList::minimumAlignment()); } + + [[nodiscard]] static std::byte* allocate(std::size_t size) noexcept; + static void deallocate(std::byte* memory, std::size_t size) noexcept; }; diff --git a/Source/MemoryAllocation/MemoryDeleter.h b/Source/MemoryAllocation/MemoryDeleter.h index 1cd676a65e1..528bbf42d43 100644 --- a/Source/MemoryAllocation/MemoryDeleter.h +++ b/Source/MemoryAllocation/MemoryDeleter.h @@ -11,7 +11,7 @@ struct MemoryDeleter { { if (memory) { std::destroy_at(memory); - MemoryAllocator::deallocate(reinterpret_cast(memory), MemoryAllocator::memoryFor()); + MemoryAllocator::deallocate(memory); } } }; @@ -29,7 +29,7 @@ struct MemoryDeleter { { if (memory) { std::destroy_n(memory, numberOfElements); - MemoryAllocator::deallocate(reinterpret_cast(memory), MemoryAllocator::memoryFor(numberOfElements)); + MemoryAllocator::deallocate(memory, numberOfElements); } } diff --git a/Source/MemoryAllocation/UniquePtr.h b/Source/MemoryAllocation/UniquePtr.h index 4cc2909fad6..e53c62e38a2 100644 --- a/Source/MemoryAllocation/UniquePtr.h +++ b/Source/MemoryAllocation/UniquePtr.h @@ -16,14 +16,14 @@ template requires (!std::is_array_v) [[nodiscard]] auto makeUniqueForOverwrite() noexcept { - return UniquePtr{ new (MemoryAllocator::allocate(MemoryAllocator::memoryFor())) T }; + return UniquePtr{ new (MemoryAllocator::allocate()) T }; } template requires std::is_unbounded_array_v [[nodiscard]] auto makeUniqueForOverwrite(std::size_t size) noexcept { - return UniquePtr{ new (MemoryAllocator::allocate(MemoryAllocator::memoryFor(size))) std::remove_extent_t[size], MemoryDeleter{ size } }; + return UniquePtr{ new (MemoryAllocator::allocate(size)) std::remove_extent_t[size], MemoryDeleter{ size } }; } template