A* Pathfinding Project  4.3.2
The A* Pathfinding Project for Unity 3D
StackPool< T > Class Template Reference

Lightweight Stack Pool. More...

Detailed Description

Lightweight Stack Pool.

Handy class for pooling stacks of type T.


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

This class is not thread safe
Version 3.2
See also

Static Public Member Functions

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

Static Private Member Functions

static StackPool ()
 Static constructor. More...

Static Private Attributes

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

Constructor & Destructor Documentation

◆ StackPool()

static StackPool ( )

Static constructor.

Member Function Documentation

◆ Claim()

static Stack<T> Claim ( )

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

◆ Clear()

static void Clear ( )

Clears all pooled stacks of this type.

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

◆ GetSize()

static int GetSize ( )

Number of stacks of this type in the pool.

◆ Release()

static void Release ( Stack< T >  stack)

Releases a stack.

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

◆ Warmup()

static void Warmup ( int  count)

Makes sure the pool contains at least count pooled items.

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

Member Data Documentation

◆ pool

readonly List<Stack<T> > pool

Internal pool.

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