Table of Contents
API reference

Class MemoryBuffer<T>

Namespace
DisCatSharp.Common.Types
Assembly
DisCatSharp.Common.dll

Provides a resizable memory buffer, which can be read from and written to. It will automatically resize whenever required.

public sealed class MemoryBuffer<T> : IMemoryBuffer<T>, IDisposable where T : unmanaged

Type Parameters

T

Type of item to hold in the buffer.

Inheritance
MemoryBuffer<T>
Implements
Inherited Members
Extension Methods

Constructors

MemoryBuffer(int, int, MemoryPool<byte>?, bool)

Creates a new buffer with a specified segment size, specified number of initially-allocated segments, and supplied memory pool.

Properties

Capacity

Gets the total capacity of this buffer. The capacity is the number of segments allocated, multiplied by size of individual segment.

Count

Gets the number of items currently written to the buffer. This number is equal to Count divided by size of T.

Length

Gets the amount of bytes currently written to the buffer. This number is never greater than Capacity .

Methods

Clear()

Resets the buffer's pointer to the beginning, allowing for reuse.

CopyTo(Stream)

Copies all the data from this buffer to a stream.

Dispose()

Disposes of any resources claimed by this buffer.

Read(ArraySegment<T>, ulong, out int)

Reads data from this buffer to specified destination array slice. This method will write either as many bytes as specified in the target slice, or however many bytes are available in this buffer, whichever is less.

Read(Span<T>, ulong, out int)

Reads data from this buffer to the specified destination buffer. This method will write either as many bytes as there are in the destination buffer, or however many bytes are available in this buffer, whichever is less.

Read(T[], int, int, ulong, out int)

Reads data from this buffer to specified destination array. This method will write either as many bytes as specified for the destination array, or however many bytes are available in this buffer, whichever is less.

ToArray()

Converts this buffer into a single continuous byte array.

Write(ArraySegment<T>)

Appends data from a supplied array slice to this buffer, growing it if necessary.

Write(Stream)

Appends data from a supplied stream to this buffer, growing it if necessary.

Write(ReadOnlySpan<T>)

Appends data from a supplied buffer to this buffer, growing it if necessary.

Write(T[], int, int)

Appends data from a supplied array to this buffer, growing it if necessary.