docs.unity3d.com

Collections 2.4.1

Search Results for

    Show / Hide Table of Contents

    Struct NativeReference<T>

    An unmanaged single value.

    Implements
    INativeDisposable
    Namespace: Unity.Collections
    Assembly: Unity.Collections.dll
    Syntax
    [NativeContainer]
    public struct NativeReference<T> : INativeDisposable where T : unmanaged
    Type Parameters
    Name Description
    T

    The type of value.

    Remarks

    The functional equivalent of an array of length 1. When you need just one value, NativeReference can be preferable to an array because it better conveys the intent.

    Constructors

    NativeReference(AllocatorHandle, NativeArrayOptions)

    Initializes and returns an instance of NativeReference.

    Declaration
    public NativeReference(AllocatorManager.AllocatorHandle allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory)
    Parameters
    Type Name Description
    AllocatorManager.AllocatorHandle allocator

    The allocator to use.

    NativeArrayOptions options

    Whether newly allocated bytes should be zeroed out.

    NativeReference(T, AllocatorHandle)

    Initializes and returns an instance of NativeReference.

    Declaration
    public NativeReference(T value, AllocatorManager.AllocatorHandle allocator)
    Parameters
    Type Name Description
    T value

    The initial value.

    AllocatorManager.AllocatorHandle allocator

    The allocator to use.

    Properties

    IsCreated

    Whether this reference has been allocated (and not yet deallocated).

    Declaration
    public readonly bool IsCreated { get; }
    Property Value
    Type Description
    bool

    True if this reference has been allocated (and not yet deallocated).

    Value

    The value stored in this reference.

    Declaration
    public T Value { get; set; }
    Property Value
    Type Description
    T

    The value stored in this reference.

    Methods

    AsReadOnly()

    Returns a read-only reference aliasing the value of this reference.

    Declaration
    public NativeReference<T>.ReadOnly AsReadOnly()
    Returns
    Type Description
    NativeReference<T>.ReadOnly

    A read-only reference aliasing the value of this reference.

    Copy(NativeReference<T>, NativeReference<T>)

    Copies the value of a reference to another reference.

    Declaration
    public static void Copy(NativeReference<T> dst, NativeReference<T> src)
    Parameters
    Type Name Description
    NativeReference<T> dst

    The destination reference.

    NativeReference<T> src

    The source reference.

    CopyFrom(NativeReference<T>)

    Copy the value of another reference to this reference.

    Declaration
    public void CopyFrom(NativeReference<T> reference)
    Parameters
    Type Name Description
    NativeReference<T> reference

    The reference to copy from.

    CopyTo(NativeReference<T>)

    Copy the value of this reference to another reference.

    Declaration
    public void CopyTo(NativeReference<T> reference)
    Parameters
    Type Name Description
    NativeReference<T> reference

    The reference to copy to.

    Dispose()

    Releases all resources (memory and safety handles).

    Declaration
    public void Dispose()

    Dispose(JobHandle)

    Creates and schedules a job that will release all resources (memory and safety handles) of this reference.

    Declaration
    public JobHandle Dispose(JobHandle inputDeps)
    Parameters
    Type Name Description
    JobHandle inputDeps

    A job handle. The newly scheduled job will depend upon this handle.

    Returns
    Type Description
    JobHandle

    The handle of a new job that will release all resources (memory and safety handles) of this reference.

    Equals(object)

    Returns true if the value stored in this reference is equal to an object.

    Declaration
    [ExcludeFromBurstCompatTesting("Takes managed object")]
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj

    An object to compare with.

    Returns
    Type Description
    bool

    True if the value stored in this reference is equal to the object.

    Overrides
    ValueType.Equals(object)
    Remarks

    Can only be equal if the object is itself a NativeReference.

    Equals(NativeReference<T>)

    Returns true if the value stored in this reference is equal to the value stored in another reference.

    Declaration
    [ExcludeFromBurstCompatTesting("Equals boxes because Value does not implement IEquatable<T>")]
    public bool Equals(NativeReference<T> other)
    Parameters
    Type Name Description
    NativeReference<T> other

    A reference to compare with.

    Returns
    Type Description
    bool

    True if the value stored in this reference is equal to the value stored in another reference.

    GetHashCode()

    Returns the hash code of this reference.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    The hash code of this reference.

    Overrides
    ValueType.GetHashCode()

    Operators

    operator ==(NativeReference<T>, NativeReference<T>)

    Returns true if the values stored in two references are equal.

    Declaration
    public static bool operator ==(NativeReference<T> left, NativeReference<T> right)
    Parameters
    Type Name Description
    NativeReference<T> left

    A reference.

    NativeReference<T> right

    Another reference.

    Returns
    Type Description
    bool

    True if the two values are equal.

    implicit operator ReadOnly(NativeReference<T>)

    Returns a read-only native reference that aliases the content of a native reference.

    Declaration
    public static implicit operator NativeReference<T>.ReadOnly(NativeReference<T> nativeReference)
    Parameters
    Type Name Description
    NativeReference<T> nativeReference

    NativeReference to alias.

    Returns
    Type Description
    NativeReference<T>.ReadOnly

    A read-only native reference that aliases the content of a native reference.

    operator !=(NativeReference<T>, NativeReference<T>)

    Returns true if the values stored in two references are unequal.

    Declaration
    public static bool operator !=(NativeReference<T> left, NativeReference<T> right)
    Parameters
    Type Name Description
    NativeReference<T> left

    A reference.

    NativeReference<T> right

    Another reference.

    Returns
    Type Description
    bool

    True if the two values are unequal.

    Implements

    INativeDisposable

    Extension Methods

    NativeReferenceUnsafeUtility.GetUnsafePtrWithoutChecks<T>(NativeReference<T>)
    NativeReferenceUnsafeUtility.GetUnsafePtr<T>(NativeReference<T>)
    NativeReferenceUnsafeUtility.GetUnsafeReadOnlyPtr<T>(NativeReference<T>)
    In This Article
    • Constructors
      • NativeReference(AllocatorHandle, NativeArrayOptions)
      • NativeReference(T, AllocatorHandle)
    • Properties
      • IsCreated
      • Value
    • Methods
      • AsReadOnly()
      • Copy(NativeReference<T>, NativeReference<T>)
      • CopyFrom(NativeReference<T>)
      • CopyTo(NativeReference<T>)
      • Dispose()
      • Dispose(JobHandle)
      • Equals(object)
      • Equals(NativeReference<T>)
      • GetHashCode()
    • Operators
      • operator ==(NativeReference<T>, NativeReference<T>)
      • implicit operator ReadOnly(NativeReference<T>)
      • operator !=(NativeReference<T>, NativeReference<T>)
    • Implements
    • Extension Methods
    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)