Class PooledSegment<T>
- Namespace
- CryptoHives.Foundation.Memory.Buffers
- Assembly
- CryptoHives.Foundation.Memory.dll
An ISegmentOwner<T> that rents a buffer from Shared and returns it automatically on dispose.
public sealed class PooledSegment<T> : ISegmentOwner<T>, IDisposable
Type Parameters
T
- Inheritance
-
PooledSegment<T>
- Implements
- Inherited Members
Remarks
Implemented as a sealed class so the backing array can never be disposed more than once by an unintended struct copy.
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
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Rent(int)
Rents a buffer with at least minimumLength elements from
Shared and returns it wrapped in a PooledSegment<T>.
public static ISegmentOwner<T> Rent(int minimumLength)
Parameters
minimumLengthintThe minimum number of elements required.
Returns
- ISegmentOwner<T>
An ISegmentOwner<T> whose Segment has Count equal to
minimumLength.
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.