Struct NativeQueue<T>
An unmanaged queue.
Namespace: Unity.Collections
Syntax
[NativeContainer]
public struct NativeQueue<T> : INativeDisposable, IDisposable where T : struct
Type Parameters
Name | Description |
---|---|
T | The type of the elements in the container. |
Constructors
NativeQueue(Allocator)
Constructs a new queue with type of memory allocation.
Declaration
public NativeQueue(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Properties
Count
The current number of items in the container.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
IsCreated
Reports whether memory for the container is allocated.
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
Boolean | True if this container object's internal storage has been allocated. |
Remarks
Note that the container storage is not created if you use the default constructor. You must specify at least an allocation type to construct a usable container.
MemoryBlockSize
Declaration
public static int MemoryBlockSize { get; }
Property Value
Type | Description |
---|---|
Int32 |
PersistentMemoryBlockCount
Declaration
public static int PersistentMemoryBlockCount { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
AsParallelWriter()
Returns parallel reader instance.
Declaration
public NativeQueue<T>.ParallelWriter AsParallelWriter()
Returns
Type | Description |
---|---|
NativeQueue.ParallelWriter<> | Parallel writer instance. |
Clear()
Clears the container.
Declaration
public void Clear()
Dequeue()
Dequeue item from the container.
Declaration
public T Dequeue()
Returns
Type | Description |
---|---|
T | Returns item from the container. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if queue is empty Count. |
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.
Enqueue(T)
Enqueue value into the container.
Declaration
public void Enqueue(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be appended. |
IsEmpty()
Reports whether container is empty.
Declaration
public bool IsEmpty()
Returns
Type | Description |
---|---|
Boolean | True if this container empty. |
Peek()
Declaration
public T Peek()
Returns
Type | Description |
---|---|
T |
ToArray(Allocator)
A copy of this queue as a NativeArray allocated with the specified type of memory.
Declaration
public NativeArray<T> ToArray(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Returns
Type | Description |
---|---|
NativeArray<T> | A NativeArray containing copies of all the items in the queue. |
TryDequeue(out T)
Try dequeueing item from the container. If container is empty item won't be changed, and return result will be false.
Declaration
public bool TryDequeue(out T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item value if dequeued. |
Returns
Type | Description |
---|---|
Boolean | Returns true if item was dequeued. |