The number of objects left in the pool
The total number of objects created by this pool
The number of used objects in the pool
Retrieves a single object. If the pool has no available objects it first hydrates the pool.
The object retrieved from the pool
Enlarges the list of available objects by the specified number.
Releases an object back into the pool
The object to be released. It should be an object previously retrieved from the pool (enforced in SlowPool
)
Generated using TypeDoc
An object pool allows to reuse the same instance of an object multiple times without the relatively costly operation of instantiating it. It's especially useful when you need to create and destroy objects quickly (eg. bullets/particles) or create a lot of them at once (eg. loading a level).
There are two implementations of Pool:
SlowPool
is useful for development and debugging, as it prevents a few incorrect usage patternsFastPoo
is intended to be used in the playable builds, it has no internal checks and is fasterTips
SlowPool
to avoid a certain class of errors from occuring, but when building the game for release go withFastPool
.FastPool
, unless you intend to useSlowPool
in the final build.