docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class UnsafeUtilityExtensions

    Provides utility methods for unsafe, untyped buffers.

    Inheritance
    object
    UnsafeUtilityExtensions
    Namespace: Unity.Collections.LowLevel.Unsafe
    Assembly: Unity.Collections.dll
    Syntax
    public static class UnsafeUtilityExtensions

    Methods

    AddressOf<T>(in T)

    Returns the address of a read-only reference.

    Declaration
    public static void* AddressOf<T>(in T value) where T : unmanaged
    Parameters
    Type Name Description
    T value

    A read-only reference.

    Returns
    Type Description
    void*

    A pointer to the referenced value.

    Type Parameters
    Name Description
    T

    The type of referenced value.

    AsRef<T>(in T)

    Returns a read-write reference from a read-only reference. Useful when you want to pass an in arg (read-only reference) where a ref arg (read-write reference) is expected. Do not mutate the referenced value, as doing so may break the runtime's assumptions.

    Declaration
    public static ref T AsRef<T>(in T value) where T : unmanaged
    Parameters
    Type Name Description
    T value

    A read-only reference.

    Returns
    Type Description
    T

    A read-write reference to the value referenced by item.

    Type Parameters
    Name Description
    T

    The type of referenced value.

    ReadArrayElementBoundsChecked<T>(void*, int, int)

    Reads an element from a buffer after bounds checking.

    Declaration
    public static T ReadArrayElementBoundsChecked<T>(void* source, int index, int capacity) where T : unmanaged
    Parameters
    Type Name Description
    void* source

    The buffer to read from.

    int index

    The index of the element.

    int capacity

    The buffer capacity (in number of elements). Used for the bounds checking.

    Returns
    Type Description
    T

    The element read from the buffer.

    Type Parameters
    Name Description
    T

    The type of element.

    Exceptions
    Type Condition
    IndexOutOfRangeException

    Thrown if the index is out of bounds.

    WriteArrayElementBoundsChecked<T>(void*, int, T, int)

    Writes an element to a buffer after bounds checking.

    Declaration
    public static void WriteArrayElementBoundsChecked<T>(void* destination, int index, T value, int capacity) where T : unmanaged
    Parameters
    Type Name Description
    void* destination

    The buffer to write to.

    int index

    The index at which to store the element.

    T value

    The value to write.

    int capacity

    The buffer capacity (in number of elements). Used for the bounds checking.

    Type Parameters
    Name Description
    T

    The type of element.

    Exceptions
    Type Condition
    IndexOutOfRangeException

    Thrown if the index is out of bounds.

    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)