Class: ResourceHeap<T>
Defined in: src/sdk/utils/resource/ResourceHeap.ts:4
A heap which allocates instances of a resource.
Type Parameters
Type Parameter |
---|
T |
Constructors
Constructor
new ResourceHeap<
T
>(factory
,destructor
,onAllocated?
,onFreed?
,initialSize?
,maxSize?
,autoShrinkThreshold?
):ResourceHeap
<T
>
Defined in: src/sdk/utils/resource/ResourceHeap.ts:21
Constructor.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
factory | () => T | undefined | A function which creates new instances of this heap's resource. |
destructor | (resource ) => void | undefined | A function which destroys instances of this heap's resource. |
onAllocated? | (resource ) => void | undefined | A function which is called when an instance of this heap's resource is allocated. |
onFreed? | (resource ) => void | undefined | A function which is called when an instance of this heap's resource is freed. |
initialSize? | number | 0 | The initial size of this heap. Defaults to 0 . |
maxSize? | number | Number.MAX_SAFE_INTEGER | The maximum size of this heap. Defaults to Number.MAX_SAFE_INTEGER . This heap cannot allocate more resources than its maximum size. |
autoShrinkThreshold? | number | Number.MAX_SAFE_INTEGER | The size above which this heap will attempt to automatically reduce its size when resources are freed. The heap will never reduce its size below this threshold. Defaults to Number.MAX_SAFE_INTEGER . |
Returns
ResourceHeap
<T
>
Properties
maxSize
readonly
maxSize:number
=Number.MAX_SAFE_INTEGER
Defined in: src/sdk/utils/resource/ResourceHeap.ts:27
The maximum size of this heap. Defaults to Number.MAX_SAFE_INTEGER
. This heap cannot allocate
more resources than its maximum size.
Methods
allocate()
allocate():
T
Defined in: src/sdk/utils/resource/ResourceHeap.ts:41
Allocates a resource instance from this heap. If this heap has an existing free resource available, one will be returned. Otherwise, a new resource instance will be created, added to the heap, and returned.
Returns
T
A resource.
Throws
Error if this heap has reached its allocation limit.
free()
free(
resource
):void
Defined in: src/sdk/utils/resource/ResourceHeap.ts:67
Frees a resource instance allocated from this heap, allowing it to be re-used.
Parameters
Parameter | Type | Description |
---|---|---|
resource | T | The resource to free. |
Returns
void