docs.unity3d.com
    Show / Hide Table of Contents

    Class NativeCopyUtility

    Utilities for copying native arrays.

    Inheritance
    Object
    NativeCopyUtility
    Namespace: UnityEngine.XR.ARSubsystems
    Syntax
    public static class NativeCopyUtility

    Methods

    CreateArrayFilledWithValue<T>(T, Int32, Allocator)

    Creates a new array allocated with allocator 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.

    Int32 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*, Int32, Int32, 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.

    Int32 sourceElementSize

    The size of one element in source.

    Int32 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 interops with structs that may change over time. This allows new fields to be added to the C# struct without breaking data obtained from data calls.

    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023