ObjectPool

class ObjectPool

ObjectPool provides the framework necessary for pooling minus the object instantiation method. You can use ObjectPoolFactory for objects that can be created using a default constructor.

Constructor


new ObjectPool(options: IObjectPoolOptions) → {}
Parameters:
Name Type Description
options IObjectPoolOptions

Summary


Properties from ObjectPool

number
protected _freeCount = 0

Number of objects in the pool. This is less than or equal to _pool.length.

Array<T>
protected _freeList

Supply pool of objects that can be used to immediately lend.

number
protected capacity

The number of objects that can be stored in the pool without allocating more space.

Methods from ObjectPool

T
allocate()

Obtains an instance from this pool.

Array<T>
allocateArray(lengthOrArray: number | T<Array>)
T
create()

Instantiates a new object of type T.

void
limit(count: number)

Dereferences objects for the GC to collect and brings the pool size down to count.

void
release(object: T)

Returns the object to the pool.

void
releaseArray(array: Array<T>)

Releases all of the objects in the passed array. These need not be allocated using allocateArray, however.

void
reserve(count: number)

Preallocates objects so that the pool size is at least count.

void
startGC(ticker: Ticker)

Install the GC on the shared ticker.

void
stopGC(ticker: Ticker)

Stops running the GC on the pool.

Protected Properties


_freeCount ObjectPool.ts:54
protected _freeCount: number = 0

Number of objects in the pool. This is less than or equal to _pool.length.

_freeList ObjectPool.ts:46
protected _freeList: Array<T>

Supply pool of objects that can be used to immediately lend.

capacity ObjectPool.ts:91
protected capacity: number

The number of objects that can be stored in the pool without allocating more space.

Public Methods


allocate ObjectPool.ts:105
allocate() → {T}

Obtains an instance from this pool.

Returns:
Type Description
T
allocateArray ObjectPool.ts:124
allocateArray(lengthOrArray: number | T<Array>) → {Array<T>}

Obtains an array of instances from this pool. This is faster than allocating multiple objects separately from this pool.

Parameters:
Name Type Description
lengthOrArray number | T<Array>

no. of objects to allocate OR the array itself into which objects are inserted. The amount to allocate is inferred from the array's length.

Returns:
Type Description
Array<T>

array of allocated objects

create ObjectPool.ts:75
create() → {T}

Instantiates a new object of type T.

Returns:
Type Description
T
limit ObjectPool.ts:244
limit(count: number) → {void}

Dereferences objects for the GC to collect and brings the pool size down to count.

Parameters:
Name Type Description
count number
Returns:
Type Description
void
release ObjectPool.ts:180
release(object: T) → {void}

Returns the object to the pool.

Parameters:
Name Type Description
object T
Returns:
Type Description
void
releaseArray ObjectPool.ts:199
releaseArray(array: Array<T>) → {void}

Releases all of the objects in the passed array. These need not be allocated using allocateArray, however.

Parameters:
Name Type Description
array Array<T>
Returns:
Type Description
void
reserve ObjectPool.ts:223
reserve(count: number) → {void}

Preallocates objects so that the pool size is at least count.

Parameters:
Name Type Description
count number
Returns:
Type Description
void
startGC ObjectPool.ts:269
startGC(ticker: Ticker) → {void}

Install the GC on the shared ticker.

Parameters:
Name Type Attributes Default Description
ticker Ticker

<optional>

Ticker.shared
Returns:
Type Description
void
stopGC ObjectPool.ts:279
stopGC(ticker: Ticker) → {void}

Stops running the GC on the pool.

Parameters:
Name Type Attributes Default Description
ticker Ticker

<optional>

Ticker.shared
Returns:
Type Description
void

Powered by webdoc!