Class GorgonNativeExtensions
Extension methods for native memory functionality.
Inherited Members
Namespace: Gorgon.Native
Assembly: Gorgon.Core.dll
Syntax
public static class GorgonNativeExtensions
Methods
| Edit this page View SourceCopyTo<T>(Stream, GorgonPtr<T>, int, int?)
Function to copy the contents of a stream into a GorgonPtr<T>.
Declaration
public static void CopyTo<T>(this Stream stream, GorgonPtr<T> pointer, int index = 0, int? count = null) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to read from. |
GorgonPtr<T> | pointer | The pointer to copy the stream data into. |
int | index | [Optional] The index within the pointer to start writing at. |
int? | count | [Optional] The maximum number of items to read from the stream. |
Type Parameters
Name | Description |
---|---|
T | The type of value in the pointer. Must be an unmanaged value type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
ArgumentOutOfRangeException | Thrown when the |
ArgumentException | Thrown if the |
EndOfStreamException | Thrown when the |
IOException | Thrown when the |
CopyTo<T>(ReadOnlyMemory<T>, GorgonPtr<T>, int)
Function to copy the contents of a memory type into a GorgonPtr<T>.
Declaration
public static void CopyTo<T>(this ReadOnlyMemory<T> memory, GorgonPtr<T> pointer, int pointerIndex = 0) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
ReadOnlyMemory<T> | memory | The memory type to copy from. |
GorgonPtr<T> | pointer | The pointer that will receive the data. |
int | pointerIndex | [Optional] The index in the pointer to start writing into. |
Type Parameters
Name | Description |
---|---|
T | The type of data in the memory type and pointer. Must be an unmanaged value type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
ArgumentOutOfRangeException | Thrown when the |
ArgumentException | -or- Thrown when the |
CopyTo<T>(ReadOnlySpan<T>, GorgonPtr<T>, int)
Function to copy the contents of a span into a GorgonPtr<T>.
Declaration
public static void CopyTo<T>(this ReadOnlySpan<T> span, GorgonPtr<T> pointer, int pointerIndex = 0) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<T> | span | The span to copy from. |
GorgonPtr<T> | pointer | The pointer that will receive the data. |
int | pointerIndex | [Optional] The index in the pointer to start writing into. |
Type Parameters
Name | Description |
---|---|
T | The type of data in the span and pointer. Must be an unmanaged value type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
ArgumentOutOfRangeException | Thrown when the |
ArgumentException | -or- Thrown when the |
CopyTo<T>(T[], GorgonPtr<T>, int, int?, int)
Function to copy the contents of an array into a GorgonPtr<T>.
Declaration
public static void CopyTo<T>(this T[] array, GorgonPtr<T> pointer, int arrayIndex = 0, int? count = null, int pointerIndex = 0) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to copy from. |
GorgonPtr<T> | pointer | The pointer that will receive the data. |
int | arrayIndex | [Optional] The index in the array to start copying from. |
int? | count | [Optional] The number of items to copy. |
int | pointerIndex | [Optional] The index in the pointer to start writing into. |
Type Parameters
Name | Description |
---|---|
T | The type of data in the array and pointer. Must be an unmanaged value type. |
Remarks
If the count
parameter is ommitted, then the full length of the source pointer, minus the arrayIndex
is used. Ensure that there is enough space in the
pointer
to accomodate the amount of data required.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
ArgumentOutOfRangeException | Thrown when the |
ArgumentException | Thrown when the -or- Thrown when the |
ToNativeBuffer<T>(Stream, int?)
Function to copy the contents of a stream into a GorgonNativeBuffer<T>.
Declaration
public static GorgonNativeBuffer<T> ToNativeBuffer<T>(this Stream stream, int? count = null) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to read from. |
int? | count | [Optional] The maximum number of items to read from the stream. |
Returns
Type | Description |
---|---|
GorgonNativeBuffer<T> | A GorgonNativeBuffer<T> containing the contents of the stream. |
Type Parameters
Name | Description |
---|---|
T | The type of value in the buffer. Must be an unmanaged value type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
EndOfStreamException | Thrown when the |
IOException | Thrown when the |
ToNativeBuffer<T>(ReadOnlyMemory<T>)
Function to copy the contents of a memory type to a GorgonNativeBuffer<T>.
Declaration
public static GorgonNativeBuffer<T> ToNativeBuffer<T>(this ReadOnlyMemory<T> memory) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
ReadOnlyMemory<T> | memory | The memory type to copy from. |
Returns
Type | Description |
---|---|
GorgonNativeBuffer<T> | A native buffer containing the contents of the memory type. |
Type Parameters
Name | Description |
---|---|
T | The type of data in the array. Must be an unmanaged value type. |
ToNativeBuffer<T>(ReadOnlySpan<T>)
Function to copy the contents of a span slice to a GorgonNativeBuffer<T>.
Declaration
public static GorgonNativeBuffer<T> ToNativeBuffer<T>(this ReadOnlySpan<T> span) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<T> | span | The span to copy from. |
Returns
Type | Description |
---|---|
GorgonNativeBuffer<T> | A native buffer containing the contents of the span. |
Type Parameters
Name | Description |
---|---|
T | The type of data in the array. Must be an unmanaged value type. |
ToNativeBuffer<T>(T[], int, int?)
Function to convert an array into a GorgonNativeBuffer<T>.
Declaration
public static GorgonNativeBuffer<T> ToNativeBuffer<T>(this T[] array, int index = 0, int? count = null) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to turn into a native buffer. |
int | index | [Optional] The index in the array that represents the beginning of the native buffer. |
int? | count | [Optional] The number of items in the array that will be contained in the buffer. |
Returns
Type | Description |
---|---|
GorgonNativeBuffer<T> | A new GorgonNativeBuffer<T> containing the |
Type Parameters
Name | Description |
---|---|
T | The type of data in the array. Must be an unmanaged value type. |
Remarks
This method copies the contents of an array into a GorgonNativeBuffer<T> so that the data can be used with native code.
If the index
is not supplied, then the beginning of the array
is used as the start of the buffer, and if the count
parameter is not
supplied, then the length of the array
(minus the index
) is used.
warning
This method copies the data from the array into the buffer. This may have a negative impact on performance and memory usage.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
ArgumentOutOfRangeException | Thrown when the |
ArgumentException | Thrown when the |
ToPinned<T>(T[], int, int?)
Function to pin an array and return a GorgonNativeBuffer<T> containing the pinned data.
Declaration
public static GorgonNativeBuffer<T> ToPinned<T>(this T[] array, int index = 0, int? count = null) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to turn into a native buffer. |
int | index | [Optional] The index in the array that represents the beginning of the native buffer. |
int? | count | [Optional] The number of items in the array that will be contained in the buffer. |
Returns
Type | Description |
---|---|
GorgonNativeBuffer<T> | A new GorgonNativeBuffer<T> containing the |
Type Parameters
Name | Description |
---|---|
T | The type of data in the array. Must be an unmanaged value type. |
Remarks
This method pins the supplied array
and returns a new GorgonNativeBuffer<T> containing the pinned data.
If the index
is not supplied, then the beginning of the array
is used as the start of the buffer, and if the count
parameter is not
supplied, then the length of the array
(minus the index
) is used.
warning
This method pins the array
, which can cause performance issues with the garbage collector. Applications should only pin their objects for a very short time for best
performance.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
ArgumentOutOfRangeException | Thrown when the |
ArgumentException | Thrown when the |