Class AllocatedSegment<T>
- Namespace
- CryptoHives.Foundation.Memory.Buffers
- Assembly
- CryptoHives.Foundation.Memory.dll
An ISegmentOwner<T> that wraps a GC-managed T array
in an ArraySegment<T>. The underlying array is eligible for garbage collection;
Dispose() only clears the segment wrapper.
public sealed class AllocatedSegment<T> : ISegmentOwner<T>, IDisposable
Type Parameters
T
- Inheritance
-
AllocatedSegment<T>
- Implements
- Inherited Members
Properties
this[int]
public T this[int i] { get; set; }
Parameters
iintZero-based index within the current segment.
Property Value
- T
Segment
Gets the current ArraySegment<T> view of the underlying array.
public ArraySegment<T> Segment { get; }
Property Value
- ArraySegment<T>
Methods
Create(T[])
Wraps buffer in an AllocatedSegment<T> covering the
full array (offset 0, length equal to the array length). No copy is made.
public static ISegmentOwner<T> Create(T[] buffer)
Parameters
bufferT[]The array to wrap.
Returns
- ISegmentOwner<T>
An ISegmentOwner<T> whose Segment references the same array as
buffer. The segment wrapper is cleared on dispose; the array itself is unaffected and remains eligible for GC.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
TrySetSegment(int, int)
Sets the offset and the length of the ArraySegment<T>.
public bool TrySetSegment(int offset, int length)
Parameters
offsetintThe new zero-based offset into the underlying array.
lengthintThe number of elements to expose starting at
offset.