Creates an object pool.
The constructor function for T
instances.
The initial size of the pool; defaults to
20
.
The amount to grow this pool by if too many
objects are borrowed; defaults to 10
.
Returns the number of currently-borrowed objects.
Returns the total number of pooled objects, borrowed or otherwise. Only really useful for debugging purposes.
Gets an object from this pool.
An object from this pool.
Acts as if all objects have been returned to this pool. This method should be used if you're implementing an algorithm that uses an arbitrary number of objects, and just want to return them all when you are done.
Returns an object to this pool.
The object to return.
true
, assuming the object was actually
from this pool, and not previously returned. In other words,
this method will only return false
if you try to
incorrectly return an object.
Returns this object as a string. Useful for debugging.
A string representation of this pool.
Generated using TypeDoc
An object pool. Useful if your game creates lots of very small objects of the same type each frame, such as a path-finding algorithm.
NOTE: The
returnObj()
method may take linear time; it's much more efficient to usereset()
if possible.