Class ListPool<T>
This class provides an interface for acquiring a System.Collections.Generic.List<T> instance from a pool. If a list is available in the pool, it will
be returned via the Get() method, otherwise a new System.Collections.Generic.List<T> instance will be created. When you are finished with
the list, it can be returned to the pool via Release(ref List<T>). The ref
keyword allows the Release(ref List<T>)
method to clear the list reference for you automatically.
Inheritance
Inherited Members
Namespace: Liminal.SDK.Collections
Assembly: Liminal.SDK.dll
Syntax
public static class ListPool<T>
Type Parameters
Name | Description |
---|---|
T | The type of the list pool. |
Remarks
The PooledList<T> struct provides a friendly interface for accessing lists from ListPool<T> via the using
syntax.
Examples
An example of how to use the ListPool<T> class.
var myIntList = ListPool<int>.Get();
myIntList.Add(100);
// .. Do something with the list contents ..
ListPool<int>.Release(ref myIntList);
System.Diagnostics.Debug.Assert(myIntList == null);
Properties
| Improve this Doc View SourcePoolCount
Gets the number of lists available in the pool.
Declaration
public static int PoolCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceGet()
Gets a System.Collections.Generic.List<T> from the pool, or creates a new one if the pool is exhausted.
Declaration
public static List<T> Get()
Returns
Type | Description |
---|---|
System.Collections.Generic.List<T> | A System.Collections.Generic.List<T> from the pool, or a new list if the pool is exhausted. |
Remarks
Make sure that you return the list to the pool using Release(ref List<T>).
Release(ref List<T>)
Clears and releases a System.Collections.Generic.List<T> to the pool. The reference is also set to null.
Declaration
public static void Release(ref List<T> list)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<T> | list | The System.Collections.Generic.List<T> to clear and return to the pool. |