Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RecyclePool<T>

Recyclable object pool. It's designed to be entirely reused each time. There is no put and get method, each time you get the data, you can use all elements as new. You shouldn't simultaneously use the same RecyclePool in more than two overlapped logic. Its size can be automatically incremented or manually resized.

see

Pool

Type parameters

  • T

Hierarchy

  • RecyclePool

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • newRecyclePool(fn: () => T, size: number): RecyclePool
  • en

    Constructor with the allocator of elements and initial pool size, all elements will be pre-allocated.

    zh

    使用元素的构造器和初始大小的构造函数,所有元素都会被预创建。

    Parameters

    • fn: () => T

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

        • (): T
        • Returns T

    • size: number

      Initial pool size

    Returns RecyclePool

Properties

Private _count

_count: number = 0

Private _data

_data: T[]

Private fn

fn: () => T

Type declaration

    • (): T
    • Returns T

Accessors

data

  • get data(): T[]

length

  • get length(): number

Methods

add

  • add(): T

removeAt

  • removeAt(idx: number): void
  • Remove an element of the object pool. This will also decrease size of the pool

    Parameters

    • idx: number

      The index of the element to be removed

    Returns void

reset

  • reset(): void

resize

  • resize(size: number): void

Generated using TypeDoc