Vixen
02b45cc4
csharp
public readonly struct PooledArray<T>

A rented array, sized to what the caller asked for and returned to the pool on Dispose. Obtained from Rent``1.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Immutable by design: nothing about the rental changes while it is held, only the contents of the span it hands out. That is what makes using var buffer = PooledArray.Rent<int>(n); behave, since a using declaration is read-only.

Fields and properties (4)

  • public Span<T> Span

    The requested elements. Never longer than asked for, even though the array is.

  • public int Length

    How many elements were requested.

  • public T[] Array

    The underlying array, which is at least Length long and usually longer. For handing to APIs that take T[]; prefer Span everywhere else.

  • public ref T this[int index]

    A reference to the element at .

Methods (7)

  • public void Dispose()

    Returns the array to the pool, clearing it first if the policy says so.

  • public Span<T>.Enumerator GetEnumerator()

    Enumerates the requested elements.

  • public bool Equals(PooledArray<T> other)

    Whether two rentals name the same array and length.

  • public override bool Equals(object? obj)

    Indicates whether this instance and a specified object are equal.

  • public override int GetHashCode()

    Returns the hash code for this instance.

  • public static bool operator ==(PooledArray<T> left, PooledArray<T> right)

    Whether two rentals name the same array and length.

  • public static bool operator !=(PooledArray<T> left, PooledArray<T> right)

    Whether two rentals name different arrays or lengths.

Used by (2)

  • PooledArrayVixen.Core
  • PoolingTestsVixen.Core.Tests