DHART
Loading...
Searching...
No Matches
DHARTAPI.NativeUtils.NativeArray< T > Class Template Reference

A read-only array stored in unmanaged memory. More...

+ Inheritance diagram for DHARTAPI.NativeUtils.NativeArray< T >:

Public Member Functions

unsafe override string ToString ()
 Get a string representation of this array. More...
 
virtual T[] CopyArray ()
 Copy the unmanaged array pointed to by this object into a managed array. More...
 
bool Equals (NativeArray< T > arr2)
 Check equality of this array and another. More...
 
- Public Member Functions inherited from DHARTAPI.NativeUtils.NativeObject
void UpdatePressure (int new_pressure)
 Update the pressure of this object.
 

Properties

virtual unsafe Span< T > array [get]
 Read only access to this unmanaged array as a span. More...
 
unsafe T this[int key] [get]
 Get the element at location i. More...
 
virtual int size [get]
 The number of elements in the array.
 
- Properties inherited from DHARTAPI.NativeUtils.NativeObject
override bool IsInvalid [get]
 There is no way to invalidate this class without destroying it, so will always return false.
 

Additional Inherited Members

- Public Attributes inherited from DHARTAPI.NativeUtils.NativeObject
int pressure
 the size of the object pointed to in unmanaged memory in bytes. Used to exert pressure on the GC. More...
 

Detailed Description

A read-only array stored in unmanaged memory.

Template Parameters
TThe type of the array pointed to in unmanaged memory.

This type supports many of the facilities of standard arrays, however, doesn't actually hold any memory itself. Instead it simply owns a map to the array in native memory which can be accessed through spans.

Note
The memory stored here is immutable, since this only holds a view to an array in C++. You can use NativeArray.CopyArray() to create a modifiable copy of this array in managed code.
See also
NativeArray.array to access the data of this array in a readable format
Type Constraints
T :struct 

Member Function Documentation

◆ CopyArray()

virtual T[] DHARTAPI.NativeUtils.NativeArray< T >.CopyArray ( )
virtual

Copy the unmanaged array pointed to by this object into a managed array.

Returns
A deep copy of the unmanaged array in managed memory.
Remarks
In most cases it is recommended to use the array property, as it saves time and memory by not copying the data into managed memory. If you must use this function to copy a large array, consider Freeing the native memory of this class by calling ReleaseHandle shortly after.

◆ Equals()

bool DHARTAPI.NativeUtils.NativeArray< T >.Equals ( NativeArray< T >  arr2)

Check equality of this array and another.

Parameters
arr2Array to check equality against
Returns
true if this array is equal to arr2

Two arrays are considered equal if they contain the same elements in the same positions, and are of the same length.

References DHARTAPI.NativeUtils.NativeArray< T >.array, and DHARTAPI.NativeUtils.NativeArray< T >.Equals().

Referenced by DHARTAPI.NativeUtils.NativeArray< T >.Equals().

◆ ToString()

unsafe override string DHARTAPI.NativeUtils.NativeArray< T >.ToString ( )

Get a string representation of this array.

Todo:
Optional toggle for truncation, and modifiable truncation threshold.
Returns
Return a string representation of all elements in this array, truncating it if necessary.

References DHARTAPI.NativeUtils.NativeArray< T >.array.

Property Documentation

◆ array

virtual unsafe Span<T> DHARTAPI.NativeUtils.NativeArray< T >.array
get

Read only access to this unmanaged array as a span.

Returns
A Span<T> referencing the entirety of the unmanaged array.
Remarks
This only returns a reference to the unmanaged array, not a copy.
See also
CopyArray for a function that copies the contents of the array.

Referenced by DHARTAPI.NativeUtils.NativeArray< T >.Equals(), and DHARTAPI.NativeUtils.NativeArray< T >.ToString().

◆ this[int key]

unsafe T DHARTAPI.NativeUtils.NativeArray< T >.this[int key]
get

Get the element at location i.

Parameters
iIndex of the element to get
Returns
The element at index i of the array.
Exceptions
ArgumentOutOfRangeExceptionthe key was beyond the bounds of this array.

The documentation for this class was generated from the following file: