Skip to content

Commit

Permalink
opt: avoid memory peak on chunk rent
Browse files Browse the repository at this point in the history
(cherry picked from commit 4e6e2c5)
  • Loading branch information
labbbirder committed May 27, 2024
1 parent 4447a73 commit e799a9e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Arch/Core/Archetype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,11 @@ public int CalculateEntitiesPerChunk(ComponentType[] types)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void EnsureChunkCapacity(int newCapacity)
{
if (ChunkCapacity >= newCapacity)
{
return;
}

// Increase chunk array size
var newChunks = ArrayPool<Chunk>.Shared.Rent(newCapacity);
Array.Copy(Chunks, newChunks, ChunkCapacity);
Expand Down

0 comments on commit e799a9e

Please sign in to comment.