Method Slice
Slice(int, int)
Slices the buffer currently in use and returns a new NatsMemoryOwner<T> instance.
public NatsMemoryOwner<T> Slice(int start, int length)
Parameters
start
intThe starting offset within the current buffer.
length
intThe length of the buffer to use.
Returns
- NatsMemoryOwner<T>
A new NatsMemoryOwner<T> instance using the target range of items.
Remarks
Using this method will dispose the current instance, and should only be used when an oversized buffer is rented and then adjusted in size, to avoid having to rent a new buffer of the new size and copy the previous items into the new one, or needing an additional variable/field to manually handle to track the used range within a given NatsMemoryOwner<T> instance.
Exceptions
- ObjectDisposedException
Thrown when the buffer in use has already been disposed.
- ArgumentOutOfRangeException
Thrown when
start
orlength
are not valid.