docs.unity3d.com
    目次を表示する/隠す

    Struct NativeReference<T>

    An unmanaged single value.

    Namespace: Unity.Collections
    Syntax
    [NativeContainer]
    public struct NativeReference<T> : INativeDisposable, IDisposable, IEquatable<NativeReference<T>> where T : struct
    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(T, AllocatorManager.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.

    NativeReference(AllocatorManager.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.

    Properties

    IsCreated

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

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

    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.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.

    Implements
    INativeDisposable.Dispose(JobHandle)

    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
    Boolean

    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
    Boolean

    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
    Int32

    The hash code of this reference.

    Overrides
    ValueType.GetHashCode()

    Operators

    Equality(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
    Boolean

    True if the two values are equal.

    Implicit(NativeReference<T> to NativeReference<T>.ReadOnly)

    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.ReadOnly<>

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

    Inequality(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
    Boolean

    True if the two values are unequal.

    Extension Methods

    NativeReferenceUnsafeUtility.GetUnsafePtr<T>(NativeReference<T>)
    NativeReferenceUnsafeUtility.GetUnsafeReadOnlyPtr<T>(NativeReference<T>)
    NativeReferenceUnsafeUtility.GetUnsafePtrWithoutChecks<T>(NativeReference<T>)
    トップに戻る
    Copyright © 2023 Unity Technologies — 商標と利用規約
    • 法律関連
    • プライバシーポリシー
    • クッキー
    • 私の個人情報を販売または共有しない
    • Your Privacy Choices (Cookie Settings)