A* Pathfinding Project  3.1.4
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Enumerations Properties Groups Pages
ListPool< T > Class Template Reference

Lightweight List Pool. More...

Static Public Member Functions

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

Static Private Member Functions

static ListPool ()
 Static constructor.
 

Static Private Attributes

static List< List< T > > pool
 Internal pool.
 

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.

Since
Version 3.2
See Also
Pathfinding.Util.StackPool

Member Function Documentation

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).

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). This list returned will have at least the capacity specified.

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.

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
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.


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