Struct NativeReference<T>
An unmanaged single value.
Implements
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 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
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
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
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
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. |
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. |