Pool

Pool

Abstract pool class for object pooling.

Constructor

new Pool(settingsopt)

Parameters:
Name Type Attributes Description
settings Object <optional>
Properties
Name Type Attributes Description
init function <optional>
create function <optional>
destroy function <optional>
Example
var vectorPool = new Pool({
    create: function () {
        return new Vector3();
    },
    init: function (x, y, z) {
        this.set(x, y, z);
    },
    destroy: function (vector) {
        vector.set(0, 0, 0);
    }
});
var vector = vectorPool.get(1, 2, 3);
vectorPool.release(vector);

Methods

get() → {Object}

Get an object from the pool if there are free ones, or create a new object.

release(object)

Put an object back into the pool.

Parameters:
Name Type Description
object Object

resize(size)

Fill the pool so it has exactly "size" objects. If the current number of objects is larger than the requested size, the excess objects are destroyed.

Parameters:
Name Type Description
size number