Table of Contents

Class ChunkTable<T>

Namespace
Typhon.Engine
Assembly
Typhon.Engine.dll

One record per chunk of a parallel dispatch: what chunk i needs to know about its work, written by the system's prepare step and read by the chunk that claims index i. Context, not the data to process — an owner id, a range, a set of cursors.

public sealed class ChunkTable<T> where T : unmanaged

Type Parameters

T

The record. Unmanaged, so the table is a flat array of values.

Inheritance
ChunkTable<T>
Inherited Members

Remarks

Who writes, who reads. Prepare runs on one thread before any chunk can be claimed: it calls Reset(int) with the dispatch's chunk count and fills every record. Chunks then reach their own record through the indexer, concurrently. Nothing writes a table while its chunks run: the next Reset(int) comes from the next dispatch's prepare, which starts only once every chunk of this one has completed (rule CD-03).

Ordering. No fence is added here, and none is needed: prepare's writes precede the dispatch's publication of its claim word (a release store) and a chunk is reached only through an Interlocked claim on that word, so every record is visible to every chunk on x64 and arm64.

By ref, never in. A record is handed out as a plain ref: in / ref readonly on a struct that is not declared readonly makes the compiler copy it before every member call, and no generic constraint can demand a readonly struct. Writing through the ref is harmless — record i is read by chunk i alone.

Cost. A read is one unsigned compare and one indexed load. The backing array grows to the largest count seen and is never shrunk, so a steady workload allocates nothing. The record's size is the author's responsibility; a record that spans a cache line or less is the one that stays cheap, since every chunk reads its own.

Constructors

ChunkTable()

public ChunkTable()

Properties

Count

The number of records the current dispatch prepared — the chunk count it was sized for.

public int Count { get; }

Property Value

int

this[int]

The record of chunk: prepare fills it, the chunk that claimed chunk reads it.

public ref T this[int chunk] { get; }

Parameters

chunk int

Property Value

T

Methods

Reset(int)

Sizes the table for a dispatch of count chunks and returns its records, zeroed, for prepare to fill. A record left over from a larger earlier dispatch is never visible: Count bounds every read.

public Span<T> Reset(int count)

Parameters

count int

Returns

Span<T>