Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Pool<T>

支持类型的对象池。这是一个传统设计的对象池,你可以从对象池中取出对象或是放回不再需要对象来复用。

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
  • 从对象池中取出一个对象。

    Returns T

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

destroy

  • destroy(dtor?: undefined | ((obj: T) => void)): void
  • 释放对象池中所有资源并清空缓存池。

    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
  • 将一个对象放回对象池中。

    Parameters

    • obj: T

      The object to be put back into the pool

    Returns void

freeArray

  • freeArray(objs: T[]): void
  • 将一组对象放回对象池中。

    Parameters

    • objs: T[]

      An array of objects to be put back into the pool

    Returns void

Generated using TypeDoc