A* Pathfinding Project  3.6.1
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
ObjectPool< T > Class Template Reference

Lightweight object Pool. More...

Detailed Description

Lightweight object Pool.

Handy class for pooling objects of type T.

Usage:

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

After you have released a object, you should never use it again.

Warning
This class is not thread safe
Since
Version 3.2
See Also
Pathfinding.Util.ListPool
Type Constraints
T :class 
T :IAstarPooledObject 
T :new() 

Static Public Member Functions

static T Claim ()
 Claim a object.
 
static void Clear ()
 Clears the pool for objects of this type.
 
static int GetSize ()
 Number of objects of this type in the pool.
 
static void Release (T obj)
 Releases an object.
 
static void Warmup (int count)
 Makes sure the pool contains at least count pooled items with capacity size.
 

Static Private Member Functions

static ObjectPool ()
 Static constructor initializing the internal pool list.
 

Static Private Attributes

static List< T > pool
 Internal pool.
 

Constructor & Destructor Documentation

static ObjectPool ( )
staticprivate

Static constructor initializing the internal pool list.

Member Function Documentation

static T Claim ( )
static

Claim a object.

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

static void Clear ( )
static

Clears the pool for objects of this type.

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

static int GetSize ( )
static

Number of objects of this type in the pool.

static void Release ( obj)
static

Releases an object.

After the object has been released it should not be used anymore.

Exceptions
System.InvalidOperationExceptionReleasing an object when it has already been released will cause an exception to be thrown. However enabling ASTAR_OPTIMIZE_POOLING will prevent this check, making this function an O(1) operation instead of O(n).
See Also
Claim
static void Warmup ( int  count)
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.

Member Data Documentation

List<T> pool
staticprivate

Internal pool.


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