Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Pool<T>

Typed object pool. It's a traditional design, you can get elements out of the pool or recycle elements by putting back into the pool.

see

RecyclePool

Type parameters

  • T

Hierarchy

  • Pool

Index

Constructors

constructor

  • newPool(ctor: () => T, elementsPerBatch: number): Pool
  • en

    Constructor with the allocator of elements and initial pool size

    zh

    使用元素的构造器和初始大小的构造函数

    Parameters

    • ctor: () => T

      The allocator of elements in pool, it's invoked directly without new

        • (): T
        • Returns T

    • elementsPerBatch: number

      Initial pool size, this size will also be the incremental size when the pool is overloaded

    Returns Pool

Properties

Private ctor

ctor: () => T

Type declaration

    • (): T
    • Returns T

Private _elementsPerBatch

_elementsPerBatch: number

Private _freepool

_freepool: T[] = []

Private _nextAvail

_nextAvail: number

Methods

alloc

  • alloc(): T
  • Take an object out of the object pool.

    Returns T

    An object ready for use. This function always return an object.

destroy

  • destroy(dtor?: undefined | ((obj: T) => void)): void
  • Destroy all elements and clear the pool.

    Parameters

    • Optional dtor: undefined | ((obj: T) => void)

      The destructor function, it will be invoked for all elements in the pool

    Returns void

free

  • free(obj: T): void
  • Put an object back into the object pool.

    Parameters

    • obj: T

      The object to be put back into the pool

    Returns void

freeArray

  • freeArray(objs: T[]): void
  • Put multiple objects back into the object pool.

    Parameters

    • objs: T[]

      An array of objects to be put back into the pool

    Returns void

Generated using TypeDoc