docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class NativeTensorArray

    Represents an area of native memory that's exposed to managed code.

    Inheritance
    object
    NativeTensorArray
    NativeTensorArrayFromManagedArray
    Implements
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.Sentis
    Assembly: Unity.Sentis.dll
    Syntax
    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 Allocator.

    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.

    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[] sourceArray, int sourceByteOffset, NativeTensorArray destinationArray, int destinationByteOffset, int lengthInBytes)
    Parameters
    Type Name Description
    byte[] sourceArray

    The array to copy from.

    int sourceByteOffset

    The offset in bytes to copy from.

    NativeTensorArray destinationArray

    The array to copy to.

    int destinationByteOffset

    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 sourceArray, int sourceOffset, byte[] destinationArray, int destinationByteOffset, int lengthInBytes)
    Parameters
    Type Name Description
    NativeTensorArray sourceArray

    The array to copy from.

    int sourceOffset

    The index of the first element to copy from.

    byte[] destinationArray

    The array to copy to.

    int destinationByteOffset

    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 sourceArray, int sourceIndex, NativeTensorArray destinationArray, int destinationIndex, int length)
    Parameters
    Type Name Description
    NativeTensorArray sourceArray

    The array to copy from.

    int sourceIndex

    The index of the first element to copy from.

    NativeTensorArray destinationArray

    The array to copy to.

    int destinationIndex

    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(NativeTensorArray, NativeTensorArray, int, int)

    Copies the data from a source NativeTensorArray to a destination NativeTensorArray up to a given length.

    Declaration
    public static void Copy(NativeTensorArray sourceArray, NativeTensorArray destinationArray, int length = -1, int srcIndex = 0)
    Parameters
    Type Name Description
    NativeTensorArray sourceArray

    The array to copy from.

    NativeTensorArray destinationArray

    The array to copy to.

    int length

    The number of elements to copy.

    int srcIndex

    The index of the first element to copy from.

    CopyTo(NativeTensorArray, int)

    Copies all of the data to a NativeTensorArray starting from a given offset.

    Declaration
    public void CopyTo(NativeTensorArray dst, int dstOffset)
    Parameters
    Type Name Description
    NativeTensorArray dst

    The NativeTensorArray to copy to.

    int dstOffset

    The index of the first element in the destination to copy to.

    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> sourceArray, int sourceIndex, NativeTensorArray destinationArray, int destinationIndex, int length) where T : unmanaged
    Parameters
    Type Name Description
    NativeArray<T> sourceArray

    The array to copy from.

    int sourceIndex

    The index of the first element to copy from.

    NativeTensorArray destinationArray

    The array to copy to.

    int destinationIndex

    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>(NativeArray<T>, NativeTensorArray, int, int)

    Copies the data from a source array to a destination NativeTensorArray up to a given length.

    Declaration
    public static void Copy<T>(NativeArray<T> sourceArray, NativeTensorArray destinationArray, int length = -1, int srcIndex = 0) where T : unmanaged
    Parameters
    Type Name Description
    NativeArray<T> sourceArray

    The array to copy from.

    NativeTensorArray destinationArray

    The array to copy to.

    int length

    The number of elements to copy.

    int srcIndex

    The index of the first element to copy from.

    Type Parameters
    Name Description
    T

    The data type of the elements.

    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 sourceArray, int sourceIndex, NativeTensorArray destinationArray, int destinationIndex, int length) where T : unmanaged
    Parameters
    Type Name Description
    NativeArray<T>.ReadOnly sourceArray

    The array to copy from.

    int sourceIndex

    The index of the first element to copy from.

    NativeTensorArray destinationArray

    The array to copy to.

    int destinationIndex

    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 sourceArray, int sourceIndex, NativeArray<T> destinationArray, int destinationIndex, int length) where T : unmanaged
    Parameters
    Type Name Description
    NativeTensorArray sourceArray

    The array to copy from.

    int sourceIndex

    The index of the first element to copy from.

    NativeArray<T> destinationArray

    The array to copy to.

    int destinationIndex

    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 sourceArray, int sourceIndex, T[] destinationArray, int destinationIndex, int length) where T : unmanaged
    Parameters
    Type Name Description
    NativeTensorArray sourceArray

    The array to copy from.

    int sourceIndex

    The index of the first element to copy from.

    T[] destinationArray

    The array to copy to.

    int destinationIndex

    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, T[], int, int)

    Copies the data from a source array to a destination array up to a given length.

    Declaration
    public static void Copy<T>(NativeTensorArray sourceArray, T[] destinationArray, int length = -1, int srcIndex = 0) where T : unmanaged
    Parameters
    Type Name Description
    NativeTensorArray sourceArray

    The array to copy from.

    T[] destinationArray

    The array to copy to.

    int length

    The number of elements to copy.

    int srcIndex

    The index of the first element to copy from.

    Type Parameters
    Name Description
    T

    The data type of the elements.

    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[] sourceArray, int sourceIndex, NativeTensorArray destinationArray, int destinationIndex, int length) where T : unmanaged
    Parameters
    Type Name Description
    T[] sourceArray

    The array to copy from.

    int sourceIndex

    The index of the first element to copy from.

    NativeTensorArray destinationArray

    The array to copy to.

    int destinationIndex

    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[], NativeTensorArray, int, int)

    Copies the data from a source array to a destination NativeTensorArray up to a given length.

    Declaration
    public static void Copy<T>(T[] sourceArray, NativeTensorArray destinationArray, int length = -1, int srcIndex = 0) where T : unmanaged
    Parameters
    Type Name Description
    T[] sourceArray

    The array to copy from.

    NativeTensorArray destinationArray

    The array to copy to.

    int length

    The number of elements to copy.

    int srcIndex

    The index of the first element to copy from.

    Type Parameters
    Name Description
    T

    The data type of the elements.

    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.

    GetReadOnlyNativeArrayHandle<T>(int, int)

    Returns the data as a NativeArray constrained to read only operations.

    Declaration
    public NativeArray<T>.ReadOnly GetReadOnlyNativeArrayHandle<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.

    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()

    Implements

    IDisposable
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)