Class UnsafeUtilityExtensions | Collections | 0.11.0-preview.17
docs.unity.cn
    Show / Hide Table of Contents

    Class UnsafeUtilityExtensions

    Unsafe utility extensions.

    Inheritance
    Object
    UnsafeUtilityExtensions
    Namespace: Unity.Collections.LowLevel.Unsafe
    Syntax
    public static class UnsafeUtilityExtensions

    Methods

    ReadArrayElementBoundsChecked<T>(Void*, Int32, Int32)

    Reads an element to an unsafe buffer after bounds checking.

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

    Source memory pointer.

    Int32 index

    Index into array.

    Int32 capacity

    Array capacity, used for bounds checking.

    Returns
    Type Description
    T

    Element read from the array.

    Type Parameters
    Name Description
    T

    Type of data in the array.

    Remarks

    Reading data out of bounds from an unsafe buffer can lead to crashes and data corruption. Unity.Collections.LowLevel.Unsafe.UnsafeUtility.ReadArrayElement``1(System.Void*,System.Int32) does not do any bounds checking, so it's fast, but provides no debugging or safety capabilities. This function provides basic bounds checking for Unity.Collections.LowLevel.Unsafe.UnsafeUtility.ReadArrayElement``1(System.Void*,System.Int32) and should be used when debuggability is required over performance.

    Exceptions
    Type Condition
    IndexOutOfRangeException

    Thrown if reading outside of the array's range.

    WriteArrayElementBoundsChecked<T>(Void*, Int32, T, Int32)

    Writes an element to an unsafe buffer after bounds checking.

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

    Destination memory pointer.

    Int32 index

    Index into array.

    T value

    Value to write into array.

    Int32 capacity

    Array capacity, used for bounds checking.

    Type Parameters
    Name Description
    T

    Type of data in the array.

    Remarks

    Writing data out of bounds to an unsafe buffer can lead to crashes and data corruption. Unity.Collections.LowLevel.Unsafe.UnsafeUtility.WriteArrayElement``1(System.Void*,System.Int32,``0) does not do any bounds checking, so it's fast, but provides no debugging or safety capabilities. This function provides basic bounds checking for Unity.Collections.LowLevel.Unsafe.UnsafeUtility.WriteArrayElement``1(System.Void*,System.Int32,``0) and should be used when debuggability is required over performance.

    Exceptions
    Type Condition
    IndexOutOfRangeException

    Thrown if element would be written outside of the array's range.

    Back to top Copyright © 2020 Unity Technologies
    Generated by DocFX
    on Friday, July 24, 2020