Struct NativeReference<T>
An unmanaged, reference container.
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 the reference in the container. |
Constructors
NativeReference(T, Allocator)
Constructs a new reference container using the specified type of memory allocation, and initialize it to specific value.
Declaration
public NativeReference(T value, Allocator allocator)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value of this container. |
| Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
NativeReference(Allocator, NativeArrayOptions)
Constructs a new reference container using the specified type of memory allocation.
Declaration
public NativeReference(Allocator allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory)
Parameters
| Type | Name | Description |
|---|---|---|
| Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
| NativeArrayOptions | options | A member of the Unity.Collections.NativeArrayOptions enumeration. |
Properties
IsCreated
Determine whether or not this container is created.
Declaration
public bool IsCreated { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Remarks
Warning: the IsCreated property can't be used to determine whether a copy of a container is still valid.
If you dispose any copy of the container, the container storage is deallocated. However, the properties of
the other copies of the container (including the original) are not updated. As a result the IsCreated property
of the copies still return true even though the container storage has been deallocated.
Accessing the data of a native container that has been disposed throws a InvalidOperationException exception.
Value
The value of this container.
Declaration
public T Value { get; set; }
Property Value
| Type | Description |
|---|---|
| T |
Methods
AsReadOnly()
Retrieve this container as read-only.
Declaration
public NativeReference<T>.ReadOnly AsReadOnly()
Returns
| Type | Description |
|---|---|
| NativeReference.ReadOnly<> | A read-only reference container. |
Copy(NativeReference<T>, NativeReference<T>)
Copy source container to destination container.
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 this container from another container.
Declaration
public void CopyFrom(NativeReference<T> reference)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeReference<T> | reference | The container to copy from. |
CopyTo(NativeReference<T>)
Copy this container to another container.
Declaration
public void CopyTo(NativeReference<T> reference)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeReference<T> | reference | The container to copy to. |
Dispose()
Disposes of this container and deallocates its memory immediately.
Declaration
public void Dispose()
Dispose(JobHandle)
Safely disposes of this container and deallocates its memory when the jobs that use it have completed.
Declaration
public JobHandle Dispose(JobHandle inputDeps)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | inputDeps | The job handle or handles for any scheduled jobs that use this container. |
Returns
| Type | Description |
|---|---|
| JobHandle | A new job handle containing the prior handles as well as the handle for the job that deletes the container. |
Implements
Remarks
You can call this function dispose of the container immediately after scheduling the job.
Pass the JobHandle returned by
the Job.Schedule
method using the jobHandle parameter so the job scheduler can dispose the container after all jobs using it have run.
Equals(Object)
Determine whether this object is equal to another object of the same type.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj | An object to compare with this object. |
Returns
| Type | Description |
|---|---|
| Boolean | true if this object is equal to the |
Overrides
Equals(NativeReference<T>)
Determine whether this container is equal to another container.
Declaration
public bool Equals(NativeReference<T> other)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeReference<T> | other | A container to compare with this container. |
Returns
| Type | Description |
|---|---|
| Boolean | true if this container is equal to the |
GetHashCode()
Returns the hash code for this container.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 | A 32-bit signed integer hash code. |
Overrides
Operators
Equality(NativeReference<T>, NativeReference<T>)
Determine whether a container is equal to another container.
Declaration
public static bool operator ==(NativeReference<T> left, NativeReference<T> right)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeReference<T> | left | Left-hand side container. |
| NativeReference<T> | right | Right-hand side container. |
Returns
| Type | Description |
|---|---|
| Boolean | true if |
Inequality(NativeReference<T>, NativeReference<T>)
Determine whether a container is not equal to another container.
Declaration
public static bool operator !=(NativeReference<T> left, NativeReference<T> right)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeReference<T> | left | Left-hand side container. |
| NativeReference<T> | right | Right-hand side container. |
Returns
| Type | Description |
|---|---|
| Boolean | true if |