docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class NativeCopyUtility

    Utilities for copying native arrays.

    Inheritance
    object
    NativeCopyUtility
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.XR.ARSubsystems
    Assembly: Unity.XR.ARSubsystems.dll
    Syntax
    public static class NativeCopyUtility

    Methods

    CopyFromReadOnlyCollection<T>(IReadOnlyCollection<T>, NativeArray<T>)

    Copies the contents of source into the NativeArray destination. The lengths of both collections must match.

    Declaration
    public static void CopyFromReadOnlyCollection<T>(IReadOnlyCollection<T> source, NativeArray<T> destination) where T : struct
    Parameters
    Type Name Description
    IReadOnlyCollection<T> source

    The IReadOnlyCollection that provides the data

    NativeArray<T> destination

    The NativeArray that will be written to

    Type Parameters
    Name Description
    T

    The type of the NativeArray structs that will be copied

    Remarks

    Prefer IReadOnlyList over IReadOnlyCollection for copy performance where possible.

    Exceptions
    Type Condition
    ArgumentException

    Thrown when there is a mismatch between source and destination sizes.

    See Also
    CopyFromReadOnlyList<T>(IReadOnlyList<T>, NativeArray<T>)

    CopyFromReadOnlyList<T>(IReadOnlyList<T>, NativeArray<T>)

    Copies the contents of source into the NativeArray destination. The lengths of both collections must match.

    Declaration
    public static void CopyFromReadOnlyList<T>(IReadOnlyList<T> source, NativeArray<T> destination) where T : struct
    Parameters
    Type Name Description
    IReadOnlyList<T> source

    The IReadOnlyList that provides the data

    NativeArray<T> destination

    The NativeArray that will be written to

    Type Parameters
    Name Description
    T

    The type of the NativeArray structs that will be copied

    Exceptions
    Type Condition
    ArgumentException

    Thrown when there is a mismatch between source and destination sizes.

    CreateArrayFilledWithValue<T>(T, int, Allocator)

    Creates a new array allocated with allocator and initialized with length copies of value.

    Declaration
    public static NativeArray<T> CreateArrayFilledWithValue<T>(T value, int length, Allocator allocator) where T : struct
    Parameters
    Type Name Description
    T value

    The value with which to fill the array.

    int length

    The length of the array to create.

    Allocator allocator

    The allocator with which to create the NativeArray.

    Returns
    Type Description
    NativeArray<T>

    A new NativeArray initialized with copies of value.

    Type Parameters
    Name Description
    T

    The type of the NativeArray to create. Must be a struct.

    FillArrayWithValue<T>(NativeArray<T>, T)

    Fills array with repeated copies of value.

    Declaration
    public static void FillArrayWithValue<T>(NativeArray<T> array, T value) where T : struct
    Parameters
    Type Name Description
    NativeArray<T> array

    The array to fill.

    T value

    The value with which to fill the array.

    Type Parameters
    Name Description
    T

    The type of the NativeArray. Must be a struct.

    PtrToNativeArrayWithDefault<T>(T, void*, int, int, Allocator)

    Creates a NativeArray from a pointer by first copying length defaultTs into the NativeArray, and then overwriting the data in the array with source, assuming each element in source is sourceElementSize bytes.

    Declaration
    public static NativeArray<T> PtrToNativeArrayWithDefault<T>(T defaultT, void* source, int sourceElementSize, int length, Allocator allocator) where T : struct
    Parameters
    Type Name Description
    T defaultT

    A default version of T, which will be used to first fill the array before copying from source.

    void* source

    A pointer to a contiguous block of data of size sourceElementSize * length.

    int sourceElementSize

    The size of one element in source.

    int length

    The number of elements to copy.

    Allocator allocator

    The allocator to use when creating the NativeArray.

    Returns
    Type Description
    NativeArray<T>

    A new NativeArray populating with defaultT and source. The caller owns the memory.

    Type Parameters
    Name Description
    T

    The type of struct to copy.

    Remarks

    This is useful for native inter-operations with structs that might change over time. This allows new fields to be added to the C# struct without breaking data obtained from data calls.

    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)