From cedd5e89a0ebdaec42ea938a51ef7c89d6ad7645 Mon Sep 17 00:00:00 2001 From: Vladislav Belov Date: Fri, 30 Oct 2026 21:27:33 +0100 Subject: [PATCH] Uses make_unique_for_overwrite in LinearAllocator We don't need to initialize that memory. libcxx currently doesn't support that. Also fixed wrong initialization order in the constructor. --- source/ps/memory/LinearAllocator.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/source/ps/memory/LinearAllocator.h b/source/ps/memory/LinearAllocator.h index ebb6419082..7ad0376121 100644 --- a/source/ps/memory/LinearAllocator.h +++ b/source/ps/memory/LinearAllocator.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace PS::Memory { @@ -33,7 +34,8 @@ namespace PS::Memory * Linear allocator (also known as an arena allocator or bump allocator) is * a simple and fast system that allocates memory sequentially from a single * growing memory buffer. Each allocation only moves a free pointer forward. - * Releasing all allocations happens at the Release call. + * Releasing all allocations happens at the Release call. The allocated memory + * is not initialized. * * It's not thread-safe. * @@ -48,7 +50,12 @@ class LinearAllocator { public: LinearAllocator(const std::size_t initialSize, const std::size_t maxCapacity) - : m_Buffer{std::make_unique(initialSize)}, m_Capacity{initialSize}, m_MaxCapacity{maxCapacity} + : m_Capacity{initialSize}, m_MaxCapacity{maxCapacity}, +#if defined(__cpp_lib_smart_ptr_for_overwrite) + m_Buffer{std::make_unique_for_overwrite(initialSize)} +#else + m_Buffer{std::make_unique(initialSize)} +#endif { ENSURE(initialSize > 0); } @@ -72,7 +79,11 @@ public: "Tried to allocate from LinearAllocator with a size of {} but the capacity is only {}", n, m_Capacity)}; } +#if defined(__cpp_lib_smart_ptr_for_overwrite) + m_Buffer = std::make_unique_for_overwrite(m_Capacity); +#else m_Buffer = std::make_unique(m_Capacity); +#endif } void* ptr{m_Buffer.get() + m_Size}; m_Size += n;