Object Pool
- Overview
- API
- Example
Objects Pool's provide an efficient alternative to contineously instantiating and destroying objects. instead objects are reused as per demand from the pool.
CBSL provides 2 general purpose object pools :-
- ObjectPool - Fixed size pool which creates objects at time of pool initialization
- LazyObjectPool - Fixed size pool which creates objects on demand (if the pool is empty)
other than this CBSL provides a IObjectPool
, it's a simple interface that you can use to implement your own object pool
#
InitializationYou can provide an IEnumerable to ObjectPool in constructor but ideally you would want to use the builder func constructor
using the func you can define how each item in the pool can be created
#
Claim & Reclaim HooksAs you can see in the above, both constructor's have onClaim
& onReclaim
Actions as optional parameters where you can define
custom login to be run on the item be claim and re-claimed. for e.g you can use these hooks to enable & disable game objects for
a game object pool
working on a tool to auto-generate api docs.
Using the object pool to reuse chunks in a voxel engine