UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

29 lines (28 loc) 522 B
class ObjectPool { _constructor; _pool = []; _count = 0; constructor(constructorFunc, size) { this._constructor = constructorFunc; this._resize(size); } _resize(size) { if (size > this._pool.length) { for (let i = this._pool.length; i < size; i++) { this._pool[i] = new this._constructor(); } } } allocate() { if (this._count >= this._pool.length) { this._resize(this._pool.length * 2); } return this._pool[this._count++]; } freeAll() { this._count = 0; } } export { ObjectPool };