Struct NativeQueue<T>
An unmanaged queue.
Implements
Namespace: Unity.Collections
Assembly: Unity.Collections.dll
Syntax
[NativeContainer]
public struct NativeQueue<T> : INativeDisposable where T : struct
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
Constructors
NativeQueue(AllocatorHandle)
Initializes and returns an instance of NativeQueue.
Declaration
public NativeQueue(AllocatorManager.AllocatorHandle allocator)
Parameters
Type | Name | Description |
---|---|---|
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
Properties
Count
Returns the current number of elements in this queue.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int | The current number of elements in this queue. |
Remarks
Note that getting the count requires traversing the queue's internal linked list of blocks. Where possible, cache this value instead of reading the property repeatedly.
IsCreated
Whether this queue has been allocated (and not yet deallocated).
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
bool | True if this queue has been allocated (and not yet deallocated). |
Methods
AsParallelWriter()
Returns a parallel writer for this queue.
Declaration
public NativeQueue<T>.ParallelWriter AsParallelWriter()
Returns
Type | Description |
---|---|
NativeQueue<T>.ParallelWriter | A parallel writer for this queue. |
Clear()
Removes all elements of this queue.
Declaration
public void Clear()
Remarks
Does not change the capacity.
Dequeue()
Removes and returns the element at the end of this queue.
Declaration
public T Dequeue()
Returns
Type | Description |
---|---|
T | The element at the end of this queue. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this queue is empty. |
Dispose()
Releases all resources (memory and safety handles).
Declaration
public void Dispose()
Dispose(JobHandle)
Creates and schedules a job that releases all resources (memory and safety handles) of this queue.
Declaration
public JobHandle Dispose(JobHandle inputDeps)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | inputDeps | The dependency for the new job. |
Returns
Type | Description |
---|---|
JobHandle | The handle of the new job. The job depends upon |
Enqueue(T)
Adds an element at the front of this queue.
Declaration
public void Enqueue(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be enqueued. |
IsEmpty()
Returns true if this queue is empty.
Declaration
public bool IsEmpty()
Returns
Type | Description |
---|---|
bool | True if the queue is empty. |
Peek()
Returns the element at the end of this queue without removing it.
Declaration
public T Peek()
Returns
Type | Description |
---|---|
T | The element at the end of this queue. |
ToArray(AllocatorHandle)
Returns an array containing a copy of this queue's content.
Declaration
public NativeArray<T> ToArray(AllocatorManager.AllocatorHandle allocator)
Parameters
Type | Name | Description |
---|---|---|
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
Returns
Type | Description |
---|---|
NativeArray<T> | An array containing a copy of this queue's content. The elements are ordered in the same order they were enqueued, e.g. the earliest enqueued element is copied to index 0 of the array. |
TryDequeue(out T)
Removes and outputs the element at the end of this queue.
Declaration
public bool TryDequeue(out T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Outputs the removed element. |
Returns
Type | Description |
---|---|
bool | True if this queue was not empty. |