PDComm.PdcommBuffer
Class
An immutable byte buffer owned by the PDComm native library.
public sealed class PdcommBuffer : IDisposableThe buffer holds a copy of the bytes passed to PdcommBuffer.Create. Dispose it to release the native memory; a finalizer releases it if you forget.
Reads (PdcommBuffer.ToArray and PdcommBuffer.TryCopy) may run concurrently from several threads. Disposal waits for in-flight reads before the native memory is released.
Members
Create
Method
Copies bytes into a new native buffer.
public static PdcommBuffer Create(ReadOnlySpan<byte> data, nuint maxBytes)The first call into the binding initializes PdcommRuntime if needed.
Parameters
| Name | Description |
|---|---|
data | The bytes to copy; may be empty. |
maxBytes | The largest accepted length, in bytes; an application policy, not a protocol constant. |
Returns
A new buffer that the caller owns and must dispose.
Notes
- Throws
PdcommException:datais longer thanmaxBytes(PdcommStatus.LimitExceeded), or the native allocation failed.
Dispose
Method
Releases the native buffer.
public void Dispose()Calling this method more than once has no effect.
ToArray
Method
Copies the buffer's contents into a new array.
public byte[] ToArray()Returns
A new array with the buffer's bytes.
Notes
- Throws
ObjectDisposedException: The buffer has been disposed. - Throws
PdcommException: The native copy failed.
TryCopy
Method
Copies the buffer's contents into a caller-supplied span when it is large enough.
public bool TryCopy(Span<byte> destination, out nuint required)Parameters
| Name | Description |
|---|---|
destination | The span that receives the bytes. |
required | When this method returns, the buffer's length in bytes. |
Returns
true if the bytes were copied; false if destination is too small, in which case it is left unchanged.
Notes
- Throws
ObjectDisposedException: The buffer has been disposed. - Throws
PdcommException: The native copy failed for a reason other than a short destination.