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

The entity to check for.

Returns

bool

true if the entity is present in this chunk; otherwise, false.

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

index int

The 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

entity Entity

The 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 T in this chunk.

Type Parameters

T

The 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

index int

The index of the entity within the chunk.

Returns

T

A readonly reference to the component data.

Type Parameters

T

The 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 T in this chunk.

Type Parameters

T

The 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

index int

The index of the entity within the chunk.

Returns

T

A reference to the component data.

Type Parameters

T

The component type.

Has(Type)

Checks if this chunk has a specific component type.

public bool Has(Type type)

Parameters

type Type

The component type to check for.

Returns

bool

true if this chunk stores components of the specified type; otherwise, false.

Has<T>()

Checks if this chunk has a specific component type.

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

Returns

bool

true if this chunk stores components of type T; otherwise, false.

Type Parameters

T

The 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

index int

The index of the entity within the chunk.

component T

The component value to set.

Type Parameters

T

The component type.