Class: ResourceHeap<T>
A heap which allocates instances of a resource.
Type parameters
Name |
---|
T |
Constructors
constructor
• new ResourceHeap<T
>(factory
, destructor
, onAllocated?
, onFreed?
, initialSize?
, maxSize?
, autoShrinkThreshold?
): ResourceHeap
<T
>
Constructor.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
factory | () => T | undefined | A function which creates new instances of this heap's resource. |
destructor | (resource : T ) => void | undefined | A function which destroys instances of this heap's resource. |
onAllocated? | (resource : T ) => void | undefined | A function which is called when an instance of this heap's resource is allocated. |
onFreed? | (resource : T ) => 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
>
Defined in
src/sdk/utils/resource/ResourceHeap.ts:21
Properties
maxSize
• Readonly
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.
Defined in
src/sdk/utils/resource/ResourceHeap.ts:27
Methods
allocate
▸ allocate(): T
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.
Defined in
src/sdk/utils/resource/ResourceHeap.ts:41
free
▸ free(resource
): void
Frees a resource instance allocated from this heap, allowing it to be re-used.
Parameters
Name | Type | Description |
---|---|---|
resource | T | The resource to free. |
Returns
void
Defined in
src/sdk/utils/resource/ResourceHeap.ts:67