Optimize RendererAllocation by reducing fragmentation with operating on power-of-2 blocks

This commit is contained in:
2026-04-28 21:55:52 +02:00
parent 378ce066cd
commit 9957166723
2 changed files with 5 additions and 0 deletions
+2
View File
@@ -220,6 +220,7 @@ void RenderFogData::Init(const RenderView& view, IFogRenderer* renderer)
void* RendererAllocation::Allocate(uintptr size)
{
PROFILE_CPU();
size = AllocationUtils::AlignToPowerOf2((int32)size); // Reduce fragmentation by operating on power-of-2 blocks
void* result = nullptr;
MemPoolLocker.Lock();
for (int32 i = 0; i < MemPool.Count(); i++)
@@ -240,6 +241,7 @@ void* RendererAllocation::Allocate(uintptr size)
void RendererAllocation::Free(void* ptr, uintptr size)
{
PROFILE_CPU();
size = AllocationUtils::AlignToPowerOf2((int32)size); // Reduce fragmentation by operating on power-of-2 blocks
MemPoolLocker.Lock();
MemPool.Add({ ptr, size });
MemPoolLocker.Unlock();
@@ -4,6 +4,9 @@
#include "Engine/Core/Memory/SimpleHeapAllocation.h"
/// <summary>
/// Shared pool allocator for the renderer used for large chunks of memory.
/// </summary>
class RendererAllocation : public SimpleHeapAllocation<RendererAllocation, 64>
{
public: