docs.unity.cn
    Show / Hide Table of Contents

    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.

    Constructors

    NativeQueue(AllocatorManager.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 readonly int Count { get; }
    Property Value
    Type Description
    Int32

    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 readonly bool IsCreated { get; }
    Property Value
    Type Description
    Boolean

    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.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 inputDeps and releases all resources (memory and safety handles) of this queue.

    Implements
    INativeDisposable.Dispose(JobHandle)

    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
    Boolean

    True if this queue has no items or if the queue has not been constructed.

    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(AllocatorManager.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
    Boolean

    True if this queue was not empty.

    Back to top Copyright © 2022 Unity Technologies
    Generated by DocFX
    on Tuesday, June 14, 2022
    Terms of use