public struct SmallList<T, TBuffer> where TBuffer : struct, IInlineBuffer<T>A list that keeps its first TBuffer.Capacity elements inside itself and only reaches for the heap beyond that.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
For the shape of data the engine is full of: descriptor slots, the children of a UI node, the bones affecting a vertex, the render passes a resource is used in. Almost always small, occasionally not, and allocating for the common case is the difference between a frame that allocates nothing and one that allocates thousands of times.
A mutable struct, with the usual caveats. Copying one copies the inline elements and shares the spill buffer, so the two diverge in a way that is hard to see. Pass it by ref, or hand out Span. Dispose it when it might have spilled — forgetting only forfeits the pooled array, it does not corrupt anything.
Fields and properties (6)
public static int InlineCapacityHow many elements fit before the list reaches for the heap.
public readonly int CountHow many elements the list holds.
public readonly bool HasSpilledWhether the list has outgrown its inline buffer.
public readonly bool IsEmptyWhether the list is empty.
public Span<T> SpanThe elements, wherever they currently live.
public ref T this[int index]A reference to the element at .
Methods (9)
public void Add(T item)Appends an element, spilling to the heap if the inline buffer is full.
public void AddRange(ReadOnlySpan<T> items)Appends a run of elements.
public bool Contains(T item)Whether the list holds an element equal to .
public void RemoveAt(int index)Removes the element at , keeping the order of the rest.
public void RemoveAtSwapBack(int index)Removes the element at by moving the last one into its place. O(1), and the right choice whenever order does not matter.
public void Clear()Empties the list. Keeps the spill buffer if there is one.
public T[] ToArray()Copies the elements into a new array.
public void Dispose()Returns the spill buffer to the pool, if there is one.
public Span<T>.Enumerator GetEnumerator()Enumerates the elements.
Used by (1)
- CollectionTestsVixen.Core.Collections.Tests