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

Lightweight Stack Pool. More...

Static Public Member Functions

static Stack< T > Claim ()
 Claim a stack.
 
static void Clear ()
 Clears all pooled stacks of this type.
 
static int GetSize ()
 Number of stacks of this type in the pool.
 
static void Release (Stack< T > stack)
 Releases a stack.
 
static void Warmup (int count)
 Makes sure the pool contains at least count pooled items.
 

Static Private Member Functions

static StackPool ()
 Static constructor.
 

Static Private Attributes

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

Detailed Description

Lightweight Stack Pool.

Handy class for pooling stacks of type T.

Usage:

  • Claim a new stack using
    Stack<SomeClass> foo = StackPool<SomeClass>.Claim ();
  • Use it and do stuff with it
  • Release it with
    StackPool<SomeClass>.Release (foo);

You do not need to clear the stack before releasing it. After you have released a stack, you should never use it again.

Since
Version 3.2
See Also
Pathfinding.Util.ListPool

Member Function Documentation

static Stack<T> Claim ( )
static

Claim a stack.

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

static void Clear ( )
static

Clears all pooled stacks of this type.

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

static void Release ( Stack< T >  stack)
static

Releases a stack.

After the stack has been released it should not be used anymore. Releasing a stack twice will cause an error.

static void Warmup ( int  count)
static

Makes sure the pool contains at least count pooled items.

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


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