A* Pathfinding Project  4.1.19
The A* Pathfinding Project for Unity 3D
ObjectPoolSimple< 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.

Since
Version 3.2
Version
Since 3.7.6 this class is thread safe
See also
Pathfinding.Util.ListPool
ObjectPool
Type Constraints
T :class 
T :new() 

Static Public Member Functions

static T Claim ()
 Claim a object. More...
 
static void Clear ()
 Clears the pool for objects of this type. More...
 
static int GetSize ()
 Number of objects of this type in the pool. More...
 
static void Release (ref T obj)
 Releases an object. More...
 

Static Private Attributes

static readonly HashSet< T > inPool = new HashSet<T>()
 
static List< T > pool = new List<T>()
 Internal pool. More...
 

Member Function Documentation

◆ Claim()

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

◆ Clear()

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.

◆ GetSize()

static int GetSize ( )
static

Number of objects of this type in the pool.

◆ Release()

static void Release ( ref T  obj)
static

Releases an object.

After the object has been released it should not be used anymore. The variable will be set to null to prevent silly mistakes.

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.
See also
Claim

Member Data Documentation

◆ inPool

readonly HashSet<T> inPool = new HashSet<T>()
staticprivate

◆ pool

List<T> pool = new List<T>()
staticprivate

Internal pool.


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