Table of Contents

Class SegmentSequence<T>

Namespace
CryptoHives.Foundation.Memory.Buffers
Assembly
CryptoHives.Foundation.Memory.dll

An ISequenceOwner<T> that adapts a single ISegmentOwner<T> into a one-node ReadOnlySequence<T>, taking over its lifetime.

public sealed class SegmentSequence<T> : ISequenceOwner<T>, IDisposable

Type Parameters

T
Inheritance
SegmentSequence<T>
Implements
Inherited Members

Remarks

This is the composition point between the two ownership abstractions: every segment strategy — PooledSegment<T>, AllocatedSegment<T>, EmptySegment<T> — becomes a sequence owner for free, so code written against ISequenceOwner<T> works with all of them without caring which is underneath.

Ownership transfers on Create(ISegmentOwner<T>): disposing this instance disposes the inner segment owner, which is what returns a pooled buffer to its pool. Do not dispose the inner owner directly after handing it over.

Properties

IsEmpty

Gets whether the owner holds no elements.

public bool IsEmpty { get; }

Property Value

bool

Length

Gets the total number of elements in Sequence.

public long Length { get; }

Property Value

long

Sequence

Gets the sequence spanning the owned buffers.

public ReadOnlySequence<T> Sequence { get; }

Property Value

ReadOnlySequence<T>

Remarks

Valid until this owner is disposed.

Methods

Create(ISegmentOwner<T>)

Wraps owner so its segment can be consumed as a ReadOnlySequence<T>, transferring ownership to the returned instance.

public static ISequenceOwner<T> Create(ISegmentOwner<T> owner)

Parameters

owner ISegmentOwner<T>

The segment owner to adopt. No copy is made.

Returns

ISequenceOwner<T>

An ISequenceOwner<T> over the same memory.

Exceptions

ArgumentNullException

owner is null.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Remarks

Disposes the adopted ISegmentOwner<T>. Idempotent.