Struct UnsafeRingQueue<T>
A fixed-size circular buffer.
Namespace: Unity.Collections.LowLevel.Unsafe
Syntax
public struct UnsafeRingQueue<T> : INativeDisposable, IDisposable where T : struct
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
Constructors
UnsafeRingQueue(T*, Int32)
Initializes and returns an instance of UnsafeRingQueue which aliasing an existing buffer.
Declaration
public UnsafeRingQueue(T*ptr, int capacity)
Parameters
Type | Name | Description |
---|---|---|
T* | ptr | An existing buffer to set as the internal buffer. |
Int32 | capacity | The capacity. |
UnsafeRingQueue(Int32, AllocatorManager.AllocatorHandle, NativeArrayOptions)
Initializes and returns an instance of UnsafeRingQueue.
Declaration
public UnsafeRingQueue(int capacity, AllocatorManager.AllocatorHandle allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory)
Parameters
Type | Name | Description |
---|---|---|
Int32 | capacity | The capacity. |
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
NativeArrayOptions | options | Whether newly allocated bytes should be zeroed out. |
Fields
Allocator
The allocator used to create the internal buffer.
Declaration
public AllocatorManager.AllocatorHandle Allocator
Field Value
Type | Description |
---|---|
AllocatorManager.AllocatorHandle | The allocator used to create the internal buffer. |
Ptr
The internal buffer where the content is stored.
Declaration
[NativeDisableUnsafePtrRestriction]
public T*Ptr
Field Value
Type | Description |
---|---|
T* | The internal buffer where the content is stored. |
Properties
Capacity
The number of elements that fit in the internal buffer.
Declaration
public readonly int Capacity { get; }
Property Value
Type | Description |
---|---|
Int32 | 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 |
---|---|
Boolean | 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 |
---|---|
Boolean | 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 |
---|---|
Int32 | 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. |
Implements
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 |
---|---|
Boolean | 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 |
---|---|
Boolean | True if the value was added. |
Remarks
Does nothing if the queue is full.