QueuePool
Provides a shared pool of Queue<T> instances to reduce allocations.
internal static class QueuePool<T>Examples
Section titled “Examples”The following example uses a pooled queue to process values in order.
using System.Collections.Generic;using Hertzole.SourceGen;
public static class QueueProcessor{ public static void Process(IEnumerable<int> values) { // The scope returns the queue to the pool when disposed. using (QueuePool<int>.Get(out Queue<int> queue)) { foreach (int value in values) { queue.Enqueue(value); }
while (queue.Count > 0) { System.Console.WriteLine(queue.Dequeue()); } } }}Methods
Section titled “Methods”Retrieves a Queue<T> from the pool.
public static Queue<T> Get();Returns
Section titled “Returns”A Queue<T> from the pool.
Get(out Queue<T>)
Section titled “Get(out Queue<T>)”Retrieves a Queue<T> from the pool and wraps it in a disposable scope that returns it automatically.
public static PoolScope<Queue<T>> Get(out Queue<T> item);When this method returns, contains the Queue<T> retrieved from the pool.
Returns
Section titled “Returns”A disposable scope that returns the Queue<T> to the pool when disposed.
Return(Queue<T>)
Section titled “Return(Queue<T>)”Returns a Queue<T> to the pool.
public static void Return(Queue<T> item);The Queue<T> to return to the pool.