Skip to content

Latest commit

 

History

History
373 lines (224 loc) · 8.37 KB

README.md

File metadata and controls

373 lines (224 loc) · 8.37 KB

@bnaya/objectbuffer

@bnaya/objectbuffer

Basic usage (Browser):

[[include:docs/codeExamples/basicUsage.js]]

Table of contents

Interfaces

Functions

Functions

acquireLock

acquireLock(agentId, objectBuffer): boolean

Tries to acquire a lock on the given objectBuffer, as the given agentId.

Parameters

Name Type
agentId number
objectBuffer any

Returns

boolean

Defined in

internal/locks.ts:19


acquireLockWait

acquireLockWait(agentId, objectBuffer, timeout): "have-lock" | "miss-lock" | "timed-out" | "no-lock"

Try to get a lock on a the given objectBuffer, or wait until timeout Will Not work on the main thread. Use only on workers Only when "have-lock" returned you actually got the lock

Uses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait under the hood

Parameters

Name Type
agentId number
objectBuffer any
timeout number

Returns

"have-lock" | "miss-lock" | "timed-out" | "no-lock"

Defined in

internal/locks.ts:76


createObjectBuffer

createObjectBuffer<T>(size, initialValue, settings?, arrayBufferKind?): T

Create a new objectBuffer, with the given initial value

Type parameters

Name Type
T T = any

Parameters

Name Type Default value Description
size number undefined The size of the ArrayBuffer to create (heap size)
initialValue T undefined
settings ObjectBufferSettings {}
arrayBufferKind ArrayBufferKind "vanilla" -

Returns

T

Defined in

internal/api.ts:39


getUnderlyingArrayBuffer

getUnderlyingArrayBuffer(objectBuffer): ArrayBuffer | SharedArrayBuffer

Parameters

Name Type
objectBuffer unknown

Returns

ArrayBuffer | SharedArrayBuffer

Defined in

internal/api.ts:131


loadObjectBuffer

loadObjectBuffer<T>(arrayBuffer, settings?): T

Create objectBuffer object from the given ArrayBuffer

The given ArrayBuffer is expected to be one obtained via getUnderlyingArrayBuffer This operation doesn't change any value in the ArrayBuffer

Type parameters

Name Type
T T = any

Parameters

Name Type
arrayBuffer ArrayBuffer | SharedArrayBuffer
settings ObjectBufferSettings

Returns

T

Defined in

internal/api.ts:146


memoryStats

memoryStats(objectBuffer): MemoryStats

Return the number of free & used bytes left in the given objectBuffer

Parameters

Name Type
objectBuffer unknown

Returns

MemoryStats

Defined in

internal/api.ts:215


processQueuedReclaims

processQueuedReclaims(objectBuffer): void

Free all the addresses collected using FinalizationRegistry When no FinalizationRegistry/WeakRef available, use disposeWrapperObject https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry

This is not called automatic by FinalizationRegistry, because It's only safe to call it when you have a lock/similar (As any other operation) And FinalizationRegistry might run when ever

Parameters

Name Type
objectBuffer unknown

Returns

void

Defined in

internal/api.ts:248


queueReclaim

queueReclaim(objectBufferPart): void

Similar to reclaim, Dispose the given objectBuffer part, make it not usable anymore, but only queue the memory for later reclaiming

see processQueuedReclaims for actually processing the reclaim

The given part should not be top level ObjectBuffer

Parameters

Name Type
objectBufferPart unknown

Returns

void

Defined in

internal/reclaim.ts:58


reclaim

reclaim(objectBufferPart): boolean

Dispose the given objectBuffer part, make it not usable anymore, immediately reclaiming memory if applicable (arc = 0 etc) To be used on systems that does not support FinalizationRegistry or for immediate and not eventual memory reclaiming

Parameters

Name Type
objectBufferPart unknown

Returns

boolean

Defined in

internal/reclaim.ts:14


releaseLock

releaseLock(agentId, objectBuffer): boolean

Try to release a lock acquired by acquireLock or acquireLockWait

Parameters

Name Type
agentId number
objectBuffer any

Returns

boolean

Defined in

internal/locks.ts:42


unstable_replaceUnderlyingArrayBuffer

unstable_replaceUnderlyingArrayBuffer(objectBuffer, newArrayBuffer): void

Replace the Underlying array buffer with the given one. The given ArrayBuffer is expected to be a copy of the prev ArrayBuffer, just bigger or smaller (less free space)

Consider using resizeObjectBuffer

unstable Due to possible issues with future support of typed arrays, and the upcoming proposal, this api function may be removed https://github.com/tc39/proposal-resizablearraybuffer

Parameters

Name Type
objectBuffer unknown
newArrayBuffer ArrayBuffer | SharedArrayBuffer

Returns

void

Defined in

internal/api.ts:189


unstable_resizeObjectBuffer

unstable_resizeObjectBuffer(objectBuffer, newSize): ArrayBuffer

Grow or shrink the underlying ArrayBuffer

unstable Due to possible issues with future support of typed arrays, and the upcoming proposal, this api function may be removed https://github.com/tc39/proposal-resizablearraybuffer

Parameters

Name Type
objectBuffer unknown
newSize number

Returns

ArrayBuffer

Defined in

internal/api.ts:107


updateObjectBufferSettings

updateObjectBufferSettings(objectBuffer, options): void

Update the settings of the given ObjectBuffer

Parameters

Name Type
objectBuffer unknown
options ObjectBufferSettings

Returns

void

Defined in

internal/api.ts:228