A* Pathfinding Project  4.0.9
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
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.
 
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 readonly List< Stack< T > > pool
 Internal pool.
 

Constructor & Destructor Documentation

static StackPool ( )
staticprivate

Static constructor.

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 int GetSize ( )
static

Number of stacks of this type in the pool.

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.

Member Data Documentation

readonly List<Stack<T> > pool
staticprivate

Internal pool.


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