ArraySliceAllocator
Namespace: SnowBank.Buffers · class
Implements: ISliceAllocator, IDisposable
Allocator that stores all data into slabs allocated from the heap.
Remarks
This buffer will allocate new slabs of memory as needed.
Slices allocated from this writer CAN be used after this instance has been disposed or cleared.
If you can guarantee that no slice allocated will survive this instance, you can also use PooledSliceAllocator which can rent memory from a pool.
Constructors
ArraySliceAllocator
ArraySliceAllocator()
Constructs a new slice allocator using the default slab and spill sizes
ArraySliceAllocator(int initialSize)
Constructs a new slice allocator using custom slab and spill sizes
ArraySliceAllocator(int initialSize, int spillSize)
Creates an instance of a ArraySliceAllocator, in which data can be written to, with an initial capacity specified.
initialSize— The initial capacity with which to initialize the underlying buffer.spillSize— The maximum required size that will be served from the pool. Larger buffer size will be allocated from the heap
Properties
FreeCapacity
int FreeCapacity { get; }
Returns the amount of space available that can still be written into without forcing the underlying buffer to grow.
MaxSlabSize
int MaxSlabSize { get; }
Maximum size of slabs allocated from the pool. Slabs with a size greater than this value will be allocated on the heap instead.
TotalAllocated
long TotalAllocated { get; }
Returns the amount of data written to the underlying buffer so far.
Methods
Allocate
ArraySegment<byte> Allocate(int size)
Returns a ArraySegment to write to that is exactly the requested size (specified by size) and advance the cursor.
size— The exact length of the returned Slice. If 0, a non-empty buffer is returned.
Returns: A ArraySegment of at exactly the size requested.
Clear
void Clear()
Clears the data written to the underlying buffers.
You must clear the before trying to re-use it.
Dispose
void Dispose()