Table of Contents

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

int

Properties

ArchetypeId

Gets the archetype this chunk belongs to.

public ArchetypeId ArchetypeId { get; }

Property Value

ArchetypeId

Capacity

Gets the maximum number of entities this chunk can hold.

public int Capacity { get; }

Property Value

int

Count

Gets the current number of entities in this chunk.

public int Count { get; }

Property Value

int

FreeSpace

Gets the amount of free space in this chunk.

public int FreeSpace { get; }

Property Value

int

IsEmpty

Gets whether this chunk is empty.

public bool IsEmpty { get; }

Property Value

bool

IsFull

Gets whether this chunk is full.

public bool IsFull { get; }

Property Value

bool

Methods

Contains(Entity)

Checks if this chunk contains the specified entity.

public bool Contains(Entity entity)

Parameters

entity Entity

Returns

bool

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>

GetEntity(int)

Gets the entity at the specified index.

public Entity GetEntity(int index)

Parameters

index int

Returns

Entity

GetEntityIndex(Entity)

Gets the index of an entity in this chunk.

public int GetEntityIndex(Entity entity)

Parameters

entity Entity

Returns

int

GetReadOnlySpan<T>()

Gets a readonly span of components.

public ReadOnlySpan<T> GetReadOnlySpan<T>() where T : struct, IComponent

Returns

ReadOnlySpan<T>

Type Parameters

T

GetReadonly<T>(int)

Gets a readonly reference to a component.

public ref readonly T GetReadonly<T>(int index) where T : struct, IComponent

Parameters

index int

Returns

T

Type Parameters

T

GetSpan<T>()

Gets a span of components for efficient iteration.

public Span<T> GetSpan<T>() where T : struct, IComponent

Returns

Span<T>

Type Parameters

T

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

index int

Returns

T

Type Parameters

T

Has(Type)

Checks if this chunk has a specific component type.

public bool Has(Type type)

Parameters

type Type

Returns

bool

Has<T>()

Checks if this chunk has a specific component type.

public bool Has<T>() where T : struct, IComponent

Returns

bool

Type Parameters

T

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

index int
component T

Type Parameters

T