diff --git a/src/Arch.Tests/WorldTest.cs b/src/Arch.Tests/WorldTest.cs
index 7138b26..130c7b9 100644
--- a/src/Arch.Tests/WorldTest.cs
+++ b/src/Arch.Tests/WorldTest.cs
@@ -240,9 +240,14 @@ public void CapacityTest()
public void EnsureCapacity()
{
using var world = World.Create();
- var archetype = world.EnsureCapacity(_entityGroup, 11000);
+ var amount = 11_000;
+ var archetype = world.EnsureCapacity(_entityGroup, amount);
+
+ // Calculation for capacity
+ var calculatedChunkSize = Archetype.GetChunkSizeInBytesFor(archetype.MinimumAmountOfEntitiesPerChunk, _entityGroup);
+ var entityCapacityPerChunk = Archetype.GetEntityCountFor(calculatedChunkSize, _entityGroup);
+ var requiredEntityCapacity = Math.Ceiling((float)amount / entityCapacityPerChunk) * entityCapacityPerChunk;
- var requiredEntityCapacity = Archetype.GetEntityCountFor(Archetype.GetByteCountFor(archetype.MinimumAmountOfEntitiesPerChunk, _entityGroup), _entityGroup);
That(world.Size, Is.EqualTo(0));
That(world.Capacity, Is.EqualTo(archetype.EntityCapacity));
That(archetype.EntityCount, Is.EqualTo(0));
diff --git a/src/Arch/Core/Archetype.cs b/src/Arch/Core/Archetype.cs
index 599fe86..a9f0306 100644
--- a/src/Arch/Core/Archetype.cs
+++ b/src/Arch/Core/Archetype.cs
@@ -283,7 +283,7 @@ internal Archetype(Signature signature)
Types = signature;
// Calculations
- ChunkSizeInBytes = GetByteCountFor(MinimumAmountOfEntitiesPerChunk, signature);
+ ChunkSizeInBytes = GetChunkSizeInBytesFor(MinimumAmountOfEntitiesPerChunk, signature);
EntitiesPerChunk = GetEntityCountFor(ChunkSizeInBytes, signature);
// The bitmask/set
@@ -757,15 +757,17 @@ public sealed partial class Archetype
{
///
- /// Calculates how many bytes are needed to store the .
+ /// Calculates the size of the memory in bytes required to store the number of .
+ /// The (L1 cache size) is taken into account and, if necessary, rounded up to a multiple of this to ensure maximum cache performance.
+ /// So if the number of exceeds the value, a multiple of this is used.
///
/// The amount of entities.
/// The component structure of the 's.
/// The amount of bytes required to store the s.
- public unsafe static int GetByteCountFor(int entityAmount, Span types)
+ public unsafe static int GetChunkSizeInBytesFor(int entityAmount, Span types)
{
var entityBytes = (sizeof(Entity) + types.ToByteSize()) * entityAmount;
- return (int)Math.Ceiling((float)entityBytes / BaseSize) * BaseSize;
+ return (int)Math.Ceiling((float)entityBytes / BaseSize) * BaseSize; // Calculates and rounds to a multiple of BaseSize to store the number of entities
}
///