Interface ISequenceOwner<T>
- Namespace
- CryptoHives.Foundation.Memory.Buffers
- Assembly
- CryptoHives.Foundation.Memory.dll
Owner of a ReadOnlySequence<T> that controls the lifetime of the buffers behind it. Implementors decide the release strategy (pool return, GC collection, or no-op) while callers use a single consistent API.
public interface ISequenceOwner<T> : IDisposable
Type Parameters
T
- Inherited Members
Examples
using SequenceLease<byte> payload = writer.LeaseSequence(); // carries the writer along
byte[] digest = Blake3.HashData(payload.Sequence); // hashed in place, no copy
Remarks
This is the sequence-shaped counterpart to ISegmentOwner<T>, and follows the same idea as IMemoryOwner<T>: the interface carries the payload, and IDisposable carries the lifetime. It exists because the borrowed sequences returned by GetReadOnlySequence() and GetReadOnlySequence() are only valid while their producer lives; an owner lets a payload outlive the object that produced it.
Ownership is exclusive. There is no reference counting: a single holder is responsible for disposal, and reading Sequence afterwards is undefined, because pooled buffers may already have been handed to another tenant.
Narrowing the payload does not require a method here, unlike
TrySetSegment(int, int) on the segment side: a
ReadOnlySequence<T> is read-only and slicing it is a cheap value operation that
leaves ownership untouched — owner.Sequence.Slice(start, length).
Built-in implementations:
- SequenceLease<T> — a payload paired with the disposable that ends its life. This is what the producers hand out, and it is a struct, so it costs nothing.
- SegmentSequence<T> — adapts any ISegmentOwner<T> into a single-segment sequence.
- EmptySequence<T> — a zero-allocation null-object sentinel.
Note that SequenceLease<T> is a struct: reaching it through this interface boxes it, which is the one allocation it exists to avoid. Take the lease by its own type unless several owner kinds genuinely have to be handled uniformly.
Properties
IsEmpty
Gets whether the owner holds no elements.
bool IsEmpty { get; }
Property Value
Length
Gets the total number of elements in Sequence.
long Length { get; }
Property Value
Sequence
Gets the sequence spanning the owned buffers.
ReadOnlySequence<T> Sequence { get; }
Property Value
Remarks
Valid until this owner is disposed.