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) → {}
Name | Type | Description |
---|---|---|
options | IObjectPoolOptions |
Summary
Properties from ObjectPool
number |
Number of objects in the pool. This is less than or equal to |
Array<T> |
Supply pool of objects that can be used to immediately lend. |
number |
The number of objects that can be stored in the pool without allocating more space. |
Methods from ObjectPool
T |
Obtains an instance from this pool. |
Array<T> |
|
T |
Instantiates a new object of type |
void |
Dereferences objects for the GC to collect and brings the pool size down to |
void |
Returns the object to the pool. |
void |
Releases all of the objects in the passed array. These need not be allocated using |
void |
Preallocates objects so that the pool size is at least |
void |
Install the GC on the shared ticker. |
void |
Stops running the GC on the pool. |
Protected Properties
protected _freeCount: number = 0
Number of objects in the pool. This is less than or equal to _pool.length
.
protected _freeList: Array<T>
Supply pool of objects that can be used to immediately lend.
protected capacity: number
The number of objects that can be stored in the pool without allocating more space.
Public Methods
allocate() → {T}
Obtains an instance from this pool.
Type | Description |
---|---|
T |
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.
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. |
Type | Description |
---|---|
Array<T> |
array of allocated objects |
create() → {T}
Instantiates a new object of type T
.
Type | Description |
---|---|
T |
limit(count: number) → {void}
Dereferences objects for the GC to collect and brings the pool size down to count
.
Name | Type | Description |
---|---|---|
count | number |
Type | Description |
---|---|
void |
release(object: T) → {void}
Returns the object to the pool.
Name | Type | Description |
---|---|---|
object | T |
Type | Description |
---|---|
void |
releaseArray(array: Array<T>) → {void}
Releases all of the objects in the passed array. These need not be allocated using allocateArray
, however.
Name | Type | Description |
---|---|---|
array | Array<T> |
Type | Description |
---|---|
void |
reserve(count: number) → {void}
Preallocates objects so that the pool size is at least count
.
Name | Type | Description |
---|---|---|
count | number |
Type | Description |
---|---|
void |
startGC(ticker: Ticker) → {void}
Install the GC on the shared ticker.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ticker | Ticker |
<optional> |
Ticker.shared |
Type | Description |
---|---|
void |
stopGC(ticker: Ticker) → {void}
Stops running the GC on the pool.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ticker | Ticker |
<optional> |
Ticker.shared |
Type | Description |
---|---|
void |