A* Pathfinding Project  4.1.19
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.

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.

Warning
This class is not thread safe
Since
Version 3.2
See also
Pathfinding.Util.ListPool

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 ( )
staticprivate

Static constructor.

Member Function Documentation

◆ Claim()

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

◆ Clear()

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

◆ GetSize()

static int GetSize ( )
static

Number of stacks of this type in the pool.

◆ Release()

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.

◆ Warmup()

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.

Member Data Documentation

◆ pool

readonly List<Stack<T> > pool
staticprivate

Internal pool.


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