@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
53 lines (52 loc) • 1.44 kB
TypeScript
/**
* A pool of reusable objects of the same type. Designed to promote reuse of objects to reduce
* garbage collection.
*
* @ignore
*/
export class ObjectPool {
/**
* @param {new (...args: any[]) => any} constructorFunc - The constructor function for the
* objects in the pool.
* @param {number} size - The initial number of object instances to allocate.
*/
constructor(constructorFunc: new (...args: any[]) => any, size: number);
/**
* The constructor function for the objects in the pool.
*
* @type {new (...args: any[]) => any}
* @private
*/
private _constructor;
/**
* Array of object instances.
*
* @type {object[]}
* @private
*/
private _pool;
/**
* The number of object instances that are currently allocated.
*
* @type {number}
* @private
*/
private _count;
/**
* @param {number} size - The number of object instances to allocate.
* @private
*/
private _resize;
/**
* Returns an object instance from the pool. If no instances are available, the pool will be
* doubled in size and a new instance will be returned.
*
* @returns {object} An object instance from the pool.
*/
allocate(): object;
/**
* All object instances in the pool will be available again. The pool itself will not be
* resized.
*/
freeAll(): void;
}