Struct NativeRingQueue<T>
A fixed-size circular buffer. For single-threaded uses only.
Implements
Namespace: Unity.Collections
Assembly: Unity.Collections.dll
Syntax
[NativeContainer]
public struct NativeRingQueue<T> : INativeDisposable where T : unmanaged
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
Remarks
This container can't be used in parallel jobs, just on single-thread (for example: main thread, or single IJob).
Constructors
NativeRingQueue(int, AllocatorHandle, NativeArrayOptions)
Initializes and returns an instance of NativeRingQueue.
Declaration
public NativeRingQueue(int capacity, AllocatorManager.AllocatorHandle allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory)
Parameters
Type | Name | Description |
---|---|---|
int | capacity | The capacity. |
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
NativeArrayOptions | options | Whether newly allocated bytes should be zeroed out. |
Properties
Capacity
The number of elements that fit in the internal buffer.
Declaration
public readonly int Capacity { get; }
Property Value
Type | Description |
---|---|
int | The number of elements that fit in the internal buffer. |
IsCreated
Whether this queue has been allocated (and not yet deallocated).
Declaration
public readonly bool IsCreated { get; }
Property Value
Type | Description |
---|---|
bool | True if this queue has been allocated (and not yet deallocated). |
IsEmpty
Whether the queue is empty.
Declaration
public readonly bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool | True if the queue is empty or the queue has not been constructed. |
Length
The number of elements currently in this queue.
Declaration
public readonly int Length { get; }
Property Value
Type | Description |
---|---|
int | The number of elements currently in this queue. |
Methods
Dequeue()
Removes the element from the end of the queue.
Declaration
public T Dequeue()
Returns
Type | Description |
---|---|
T | Returns the removed element. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the queue was empty. |
Dispose()
Releases all resources (memory and safety handles).
Declaration
public void Dispose()
Dispose(JobHandle)
Creates and schedules a job that will dispose this queue.
Declaration
public JobHandle Dispose(JobHandle inputDeps)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | inputDeps | The handle of a job which the new job will depend upon. |
Returns
Type | Description |
---|---|
JobHandle | The handle of a new job that will dispose this queue. The new job depends upon inputDeps. |
Enqueue(T)
Adds an element at the front of the queue.
Declaration
public void Enqueue(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be added. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the queue was full. |
TryDequeue(out T)
Removes the element from the end of the queue.
Declaration
public bool TryDequeue(out T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Outputs the element removed. |
Returns
Type | Description |
---|---|
bool | True if an element was removed. |
Remarks
Does nothing if the queue is empty.
TryEnqueue(T)
Adds an element at the front of the queue.
Declaration
public bool TryEnqueue(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be added. |
Returns
Type | Description |
---|---|
bool | True if the value was added. |
Remarks
Does nothing if the queue is full.