Class NativeTensorArray
Represents an area of native memory that's exposed to managed code.
Implements
Inherited Members
Namespace: Unity.InferenceEngine
Assembly: Unity.InferenceEngine.dll
Syntax
[MovedFrom("Unity.Sentis")]
public class NativeTensorArray : IDisposable
  Constructors
NativeTensorArray(int, bool, Allocator)
Initializes and returns an instance of NativeTensorArray with a given length.
Declaration
public NativeTensorArray(int length, bool clearOnInit = false, Allocator allocator = Allocator.Persistent)
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | length | The integer number of elements to allocate.  | 
      
| bool | clearOnInit | Whether to zero the data after allocating.  | 
      
| Allocator | allocator | The allocation type to use as an   | 
      
NativeTensorArray(SafeHandle, int)
Initializes and returns an instance of NativeTensorArray with a preexisting handle.
Declaration
protected NativeTensorArray(SafeHandle safeHandle, int dataLength)
  Parameters
| Type | Name | Description | 
|---|---|---|
| SafeHandle | safeHandle | The safe handle to the data.  | 
      
| int | dataLength | The integer number of elements.  | 
      
Fields
k_DataItemSize
Size in bytes of an individual element.
Declaration
public const int k_DataItemSize = 4
  Field Value
| Type | Description | 
|---|---|
| int | 
Properties
Disposed
Whether the backing data is disposed.
Declaration
public bool Disposed { get; }
  Property Value
| Type | Description | 
|---|---|
| bool | 
Length
The number of allocated elements.
Declaration
public int Length { get; }
  Property Value
| Type | Description | 
|---|---|
| int | 
RawPtr
The raw pointer of the backing data.
Declaration
public virtual void* RawPtr { get; }
  Property Value
| Type | Description | 
|---|---|
| void* | 
Methods
AddressAt<T>(long)
Returns the raw pointer of the backing data at a given index.
Declaration
public T* AddressAt<T>(long index) where T : unmanaged
  Parameters
| Type | Name | Description | 
|---|---|---|
| long | index | The index of the element.  | 
      
Returns
| Type | Description | 
|---|---|
| T* | The raw pointer to the element in the data.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The type of the element.  | 
      
AsReadOnlyNativeArray<T>(int, int)
Returns the data as a NativeArray constrained to read only operations.
Declaration
public NativeArray<T>.ReadOnly AsReadOnlyNativeArray<T>(int dstCount, int srcOffset = 0) where T : unmanaged
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | dstCount | The number of elements.  | 
      
| int | srcOffset | The index of the first element.  | 
      
Returns
| Type | Description | 
|---|---|
| NativeArray<T>.ReadOnly | The read only native array of the data.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The type of the data.  | 
      
AsReadOnlySpan<T>(int, int)
Returns the data as a ReadOnlySpan.
Declaration
public ReadOnlySpan<T> AsReadOnlySpan<T>(int dstCount, int srcOffset = 0) where T : unmanaged
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | dstCount | The number of elements.  | 
      
| int | srcOffset | The index of the first element.  | 
      
Returns
| Type | Description | 
|---|---|
| ReadOnlySpan<T> | The span of the data.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The type of the data.  | 
      
BlockCopy(byte[], int, NativeTensorArray, int, int)
Copies the data from a source byte array to a destination NativeTensorArray up to a given length starting from given offsets.
Declaration
public static void BlockCopy(byte[] src, int srcByteIndex, NativeTensorArray dst, int dstByteIndex, int lengthInBytes)
  Parameters
| Type | Name | Description | 
|---|---|---|
| byte[] | src | The array to copy from.  | 
      
| int | srcByteIndex | The offset in bytes to copy from.  | 
      
| NativeTensorArray | dst | The array to copy to.  | 
      
| int | dstByteIndex | The offset in bytes to copy to in the destination array.  | 
      
| int | lengthInBytes | The number of bytes to copy.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown if the given indexes and length are out of bounds of the source or destination array.  | 
      
BlockCopy(NativeTensorArray, int, byte[], int, int)
Copies the data from a source NativeTensorArray to a destination byte array up to a given length starting from given offsets.
Declaration
public static void BlockCopy(NativeTensorArray src, int srcByteIndex, byte[] dst, int dstByteIndex, int lengthInBytes)
  Parameters
| Type | Name | Description | 
|---|---|---|
| NativeTensorArray | src | The array to copy from.  | 
      
| int | srcByteIndex | The index of the first element to copy from.  | 
      
| byte[] | dst | The array to copy to.  | 
      
| int | dstByteIndex | The offset in bytes to copy to in the destination array.  | 
      
| int | lengthInBytes | The number of bytes to copy.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown if the given indexes and length are out of bounds of the source or destination array.  | 
      
Copy(NativeTensorArray, int, NativeTensorArray, int, int)
Copies the data from a source NativeTensorArray to a destination NativeTensorArray up to a given length starting from given indexes.
Declaration
public static void Copy(NativeTensorArray src, int srcIndex, NativeTensorArray dst, int dstIndex, int length)
  Parameters
| Type | Name | Description | 
|---|---|---|
| NativeTensorArray | src | The array to copy from.  | 
      
| int | srcIndex | The index of the first element to copy from.  | 
      
| NativeTensorArray | dst | The array to copy to.  | 
      
| int | dstIndex | The index of the first element to copy to.  | 
      
| int | length | The number of elements.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown if the given indexes and length are out of bounds of the source or destination array.  | 
      
Copy<T>(NativeArray<T>, int, NativeTensorArray, int, int)
Copies the data from a source NativeArray to a destination array up to a given length starting from given indexes.
Declaration
public static void Copy<T>(NativeArray<T> src, int srcIndex, NativeTensorArray dst, int dstIndex, int length) where T : unmanaged
  Parameters
| Type | Name | Description | 
|---|---|---|
| NativeArray<T> | src | The array to copy from.  | 
      
| int | srcIndex | The index of the first element to copy from.  | 
      
| NativeTensorArray | dst | The array to copy to.  | 
      
| int | dstIndex | The index of the first element to copy to.  | 
      
| int | length | The number of elements.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The data type of the elements.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown if the given indexes and length are out of bounds of the source or destination array.  | 
      
Copy<T>(ReadOnly, int, NativeTensorArray, int, int)
Copies the data from a source NativeArray to a destination array up to a given length starting from given indexes.
Declaration
public static void Copy<T>(NativeArray<T>.ReadOnly src, int srcIndex, NativeTensorArray dst, int dstIndex, int length) where T : unmanaged
  Parameters
| Type | Name | Description | 
|---|---|---|
| NativeArray<T>.ReadOnly | src | The array to copy from.  | 
      
| int | srcIndex | The index of the first element to copy from.  | 
      
| NativeTensorArray | dst | The array to copy to.  | 
      
| int | dstIndex | The index of the first element to copy to.  | 
      
| int | length | The number of elements.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The data type of the elements.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown if the given indexes and length are out of bounds of the source or destination array.  | 
      
Copy<T>(NativeTensorArray, int, NativeArray<T>, int, int)
Copies the data from a source NativeTensorArray to a destination array up to a given length starting from given indexes.
Declaration
public static void Copy<T>(NativeTensorArray src, int srcIndex, NativeArray<T> dst, int dstIndex, int length) where T : unmanaged
  Parameters
| Type | Name | Description | 
|---|---|---|
| NativeTensorArray | src | The array to copy from.  | 
      
| int | srcIndex | The index of the first element to copy from.  | 
      
| NativeArray<T> | dst | The array to copy to.  | 
      
| int | dstIndex | The index of the first element to copy to.  | 
      
| int | length | The number of elements.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The data type of the elements.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown if the given indexes and length are out of bounds of the source or destination array.  | 
      
Copy<T>(NativeTensorArray, int, T[], int, int)
Copies the data from a source NativeTensorArray to a destination array up to a given length starting from given indexes.
Declaration
public static void Copy<T>(NativeTensorArray src, int srcIndex, T[] dst, int dstIndex, int length) where T : unmanaged
  Parameters
| Type | Name | Description | 
|---|---|---|
| NativeTensorArray | src | The array to copy from.  | 
      
| int | srcIndex | The index of the first element to copy from.  | 
      
| T[] | dst | The array to copy to.  | 
      
| int | dstIndex | The index of the first element to copy to.  | 
      
| int | length | The number of elements.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The data type of the elements.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown if the given indexes and length are out of bounds of the source or destination array.  | 
      
Copy<T>(T[], int, NativeTensorArray, int, int)
Copies the data from a source array to a destination NativeTensorArray up to a given length starting from given indexes.
Declaration
public static void Copy<T>(T[] src, int srcIndex, NativeTensorArray dst, int dstIndex, int length) where T : unmanaged
  Parameters
| Type | Name | Description | 
|---|---|---|
| T[] | src | The array to copy from.  | 
      
| int | srcIndex | The index of the first element to copy from.  | 
      
| NativeTensorArray | dst | The array to copy to.  | 
      
| int | dstIndex | The index of the first element to copy to.  | 
      
| int | length | The number of elements.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The data type of the elements.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown if the given indexes and length are out of bounds of the source or destination array.  | 
      
Dispose()
Disposes of the array and any associated memory.
Declaration
public virtual void Dispose()
  GetNativeArrayHandle<T>()
Returns the data converted to a NativeArray.
Declaration
public NativeArray<T> GetNativeArrayHandle<T>() where T : unmanaged
  Returns
| Type | Description | 
|---|---|
| NativeArray<T> | The converted native array from data.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The type of the data.  | 
      
Get<T>(int)
Returns the value of the backing data at a given index.
Declaration
public T Get<T>(int index) where T : unmanaged
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | index | The index of the element.  | 
      
Returns
| Type | Description | 
|---|---|
| T | The value of the element in the data.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The type of the element.  | 
      
Set<T>(int, T)
Sets the value of the backing data at a given index.
Declaration
public void Set<T>(int index, T value) where T : unmanaged
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | index | The index of the element.  | 
      
| T | value | The value to set at the index.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The type of the element.  | 
      
ToArray<T>(int, int)
Returns the data as an array.
Declaration
public T[] ToArray<T>(int dstCount, int srcOffset = 0) where T : unmanaged
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | dstCount | The number of elements.  | 
      
| int | srcOffset | The index of the first element.  | 
      
Returns
| Type | Description | 
|---|---|
| T[] | The copied array of the data.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| T | The type of the data.  | 
      
ZeroMemory()
Clears the allocated memory to zero.
Declaration
public void ZeroMemory()