A* Pathfinding Project  4.1.21
The A* Pathfinding Project for Unity 3D
ListPool< T > Class Template Reference

Lightweight List Pool. More...

Detailed Description

Lightweight List Pool.

Handy class for pooling lists of type T.

Usage:

  • Claim a new list using
    List<SomeClass> foo = ListPool<SomeClass>.Claim ();
  • Use it and do stuff with it
  • Release it with
    ListPool<SomeClass>.Release (foo);

You do not need to clear the list before releasing it. After you have released a list, you should never use it again, if you do use it, you will mess things up quite badly in the worst case.

Since
Version 3.2
See also
Pathfinding.Util.StackPool

Static Public Member Functions

static List< T > Claim ()
 Claim a list. More...
 
static List< T > Claim (int capacity)
 Claim a list with minimum capacity Returns a pooled list if any are in the pool. More...
 
static void Clear ()
 Clears the pool for lists of this type. More...
 
static int GetSize ()
 Number of lists of this type in the pool. More...
 
static void Release (ref List< T > list)
 Releases a list and sets the variable to null. More...
 
static void Release (List< T > list)
 Releases a list. More...
 
static void Warmup (int count, int size)
 Makes sure the pool contains at least count pooled items with capacity size. More...
 

Static Private Member Functions

static int FindCandidate (List< List< T > > pool, int capacity)
 

Private Attributes

const int LargeThreshold = 5000
 
const int MaxCapacitySearchLength = 8
 When requesting a list with a specified capacity, search max this many lists in the pool before giving up. More...
 
const int MaxLargePoolSize = 8
 

Static Private Attributes

static readonly HashSet< List< T > > inPool = new HashSet<List<T> >()
 
static readonly List< List< T > > largePool = new List<List<T> >()
 
static readonly List< List< T > > pool = new List<List<T> >()
 Internal pool. More...
 

Member Function Documentation

◆ Claim() [1/2]

static List<T> Claim ( )
static

Claim a list.

Returns a pooled list if any are in the pool. Otherwise it creates a new one. After usage, this list should be released using the Release function (though not strictly necessary).

◆ Claim() [2/2]

static List<T> Claim ( int  capacity)
static

Claim a list with minimum capacity Returns a pooled list if any are in the pool.

Otherwise it creates a new one. After usage, this list should be released using the Release function (though not strictly necessary). A subset of the pool will be searched for a list with a high enough capacity and one will be returned if possible, otherwise the list with the largest capacity found will be returned.

◆ Clear()

static void Clear ( )
static

Clears the pool for lists of this type.

This is an O(n) operation, where n is the number of pooled lists.

◆ FindCandidate()

static int FindCandidate ( List< List< T > >  pool,
int  capacity 
)
staticprivate

◆ GetSize()

static int GetSize ( )
static

Number of lists of this type in the pool.

◆ Release() [1/2]

static void Release ( ref List< T >  list)
static

Releases a list and sets the variable to null.

After the list has been released it should not be used anymore.

Exceptions
System.InvalidOperationExceptionReleasing a list when it has already been released will cause an exception to be thrown.
See also
Claim

◆ Release() [2/2]

static void Release ( List< T >  list)
static

Releases a list.

After the list has been released it should not be used anymore.

Exceptions
System.InvalidOperationExceptionReleasing a list when it has already been released will cause an exception to be thrown.
See also
Claim

◆ Warmup()

static void Warmup ( int  count,
int  size 
)
static

Makes sure the pool contains at least count pooled items with capacity size.

This is good if you want to do all allocations at start.

Member Data Documentation

◆ inPool

readonly HashSet<List<T> > inPool = new HashSet<List<T> >()
staticprivate

◆ largePool

readonly List<List<T> > largePool = new List<List<T> >()
staticprivate

◆ LargeThreshold

const int LargeThreshold = 5000
private

◆ MaxCapacitySearchLength

const int MaxCapacitySearchLength = 8
private

When requesting a list with a specified capacity, search max this many lists in the pool before giving up.

Must be greater or equal to one.

◆ MaxLargePoolSize

const int MaxLargePoolSize = 8
private

◆ pool

readonly List<List<T> > pool = new List<List<T> >()
staticprivate

Internal pool.


The documentation for this class was generated from the following file: