Class ArchetypeChunk
- Namespace
- KeenEyes
- Assembly
- KeenEyes.Core.dll
A fixed-size block of entity storage within an archetype. Chunks provide cache-friendly memory layout and enable pooling for reduced GC pressure.
public sealed class ArchetypeChunk : IDisposable
- Inheritance
-
ArchetypeChunk
- Implements
- Inherited Members
Remarks
Each chunk stores up to Capacity entities with their components in parallel arrays. The fixed size (typically sized to fit in L2 cache) enables:
- Predictable memory layout for cache efficiency
- Chunk reuse through pooling when entities are removed
- Parallel processing of different chunks by multiple threads
When a chunk becomes empty, it can be returned to the ChunkPool for reuse by the same or different archetypes.
Fields
DefaultCapacity
Default chunk capacity - sized to keep total chunk memory around 16KB.
public const int DefaultCapacity = 128
Field Value
Properties
ArchetypeId
Gets the archetype this chunk belongs to.
public ArchetypeId ArchetypeId { get; }
Property Value
Capacity
Gets the maximum number of entities this chunk can hold.
public int Capacity { get; }
Property Value
Count
Gets the current number of entities in this chunk.
public int Count { get; }
Property Value
FreeSpace
Gets the amount of free space in this chunk.
public int FreeSpace { get; }
Property Value
IsEmpty
Gets whether this chunk is empty.
public bool IsEmpty { get; }
Property Value
IsFull
Gets whether this chunk is full.
public bool IsFull { get; }
Property Value
Methods
Contains(Entity)
Checks if this chunk contains the specified entity.
public bool Contains(Entity entity)
Parameters
entityEntityThe entity to check for.
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetEntities()
Gets a span of all entities in this chunk.
public ReadOnlySpan<Entity> GetEntities()
Returns
- ReadOnlySpan<Entity>
A readonly span over all entities currently stored in this chunk.
GetEntity(int)
Gets the entity at the specified index.
public Entity GetEntity(int index)
Parameters
indexintThe index of the entity within the chunk.
Returns
- Entity
The entity stored at the specified index.
GetEntityIndex(Entity)
Gets the index of an entity in this chunk.
public int GetEntityIndex(Entity entity)
Parameters
entityEntityThe entity to locate.
Returns
- int
The index of the entity within the chunk, or -1 if it is not present.
GetReadOnlySpan<T>()
Gets a readonly span of components.
public ReadOnlySpan<T> GetReadOnlySpan<T>() where T : struct, IComponent
Returns
- ReadOnlySpan<T>
A readonly span over all component values of type
Tin this chunk.
Type Parameters
TThe component type.
GetReadonly<T>(int)
Gets a readonly reference to a component.
public ref readonly T GetReadonly<T>(int index) where T : struct, IComponent
Parameters
indexintThe index of the entity within the chunk.
Returns
- T
A readonly reference to the component data.
Type Parameters
TThe component type.
GetSpan<T>()
Gets a span of components for efficient iteration.
public Span<T> GetSpan<T>() where T : struct, IComponent
Returns
- Span<T>
A span over all component values of type
Tin this chunk.
Type Parameters
TThe component type.
Get<T>(int)
Gets a reference to a component for the entity at the specified index.
public ref T Get<T>(int index) where T : struct, IComponent
Parameters
indexintThe index of the entity within the chunk.
Returns
- T
A reference to the component data.
Type Parameters
TThe component type.
Has(Type)
Checks if this chunk has a specific component type.
public bool Has(Type type)
Parameters
typeTypeThe component type to check for.
Returns
Has<T>()
Checks if this chunk has a specific component type.
public bool Has<T>() where T : struct, IComponent
Returns
Type Parameters
TThe component type to check for.
Set<T>(int, in T)
Sets a component value at the specified index.
public void Set<T>(int index, in T component) where T : struct, IComponent
Parameters
indexintThe index of the entity within the chunk.
componentTThe component value to set.
Type Parameters
TThe component type.