Interface IMemoryBuffer<T>
An interface describing the API of resizable memory buffers, such as MemoryBuffer<T> and ContinuousMemoryBuffer<T>.
Namespace: DisCatSharp.Common.Types
Assembly: DisCatSharp.Common.dll
Syntax
public interface IMemoryBuffer<T> : IDisposable where T : struct
Type Parameters
Name | Description |
---|---|
T | Type of item to hold in the buffer. |
Properties
| Improve this Doc View SourceCapacity
Gets the total capacity of this buffer. The capacity is the number of segments allocated, multiplied by size of individual segment.
Declaration
ulong Capacity { get; }
Property Value
Type | Description |
---|---|
System.UInt64 |
Count
Gets the number of items currently written to the buffer. This number is equal to Count divided by size of T
.
Declaration
ulong Count { get; }
Property Value
Type | Description |
---|---|
System.UInt64 |
Length
Gets the amount of bytes currently written to the buffer. This number is never greater than Capacity.
Declaration
ulong Length { get; }
Property Value
Type | Description |
---|---|
System.UInt64 |
Methods
| Improve this Doc View SourceClear()
Resets the buffer's pointer to the beginning, allowing for reuse.
Declaration
void Clear()
CopyTo(Stream)
Copies all the data from this buffer to a stream.
Declaration
void CopyTo(Stream destination)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | destination | Stream to copy this buffer's data to. |
Read(T[], Int32, Int32, UInt64, out Int32)
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.
Declaration
bool Read(T[] data, int start, int count, ulong source, out int itemsWritten)
Parameters
Type | Name | Description |
---|---|---|
T[] | data | Array to read the data from this buffer into. |
System.Int32 | start | Starting position in the target array to write to. |
System.Int32 | count | Maximum number of bytes to write to target array. |
System.UInt64 | source | Starting position in this buffer to read from. |
System.Int32 | itemsWritten | Number of items written to the destination buffer. |
Returns
Type | Description |
---|---|
System.Boolean | Whether more data is available in this buffer. |
Read(ArraySegment<T>, UInt64, out Int32)
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.
Declaration
bool Read(ArraySegment<T> data, ulong source, out int itemsWritten)
Parameters
Type | Name | Description |
---|---|---|
System.ArraySegment<T> | data | |
System.UInt64 | source | |
System.Int32 | itemsWritten | Number of items written to the destination buffer. |
Returns
Type | Description |
---|---|
System.Boolean | Whether more data is available in this buffer. |
Read(Span<T>, UInt64, out Int32)
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.
Declaration
bool Read(Span<T> destination, ulong source, out int itemsWritten)
Parameters
Type | Name | Description |
---|---|---|
System.Span<T> | destination | Buffer to read the data from this buffer into. |
System.UInt64 | source | Starting position in this buffer to read from. |
System.Int32 | itemsWritten | Number of items written to the destination buffer. |
Returns
Type | Description |
---|---|
System.Boolean | Whether more data is available in this buffer. |
ToArray()
Converts this buffer into a single continuous byte array.
Declaration
T[] ToArray()
Returns
Type | Description |
---|---|
T[] | Converted byte array. |
Write(T[], Int32, Int32)
Appends data from a supplied array to this buffer, growing it if necessary.
Declaration
void Write(T[] data, int start, int count)
Parameters
Type | Name | Description |
---|---|---|
T[] | data | Array containing data to write. |
System.Int32 | start | Index from which to start reading the data. |
System.Int32 | count | Number of bytes to read from the source. |
Write(ArraySegment<T>)
Appends data from a supplied array slice to this buffer, growing it if necessary.
Declaration
void Write(ArraySegment<T> data)
Parameters
Type | Name | Description |
---|---|---|
System.ArraySegment<T> | data | Array slice containing data to write. |
Write(Stream)
Appends data from a supplied stream to this buffer, growing it if necessary.
Declaration
void Write(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | Stream to copy data from. |
Write(ReadOnlySpan<T>)
Appends data from a supplied buffer to this buffer, growing it if necessary.
Declaration
void Write(ReadOnlySpan<T> data)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<T> | data | Buffer containing data to write. |