heapForSize

abstract fun heapForSize(n: Int, unsigned: Boolean): TypedArray<*, *, *, *>(source)

Requires n to be one of:

  • integer 8, 16, or 32.

  • A integer-type TypedArray constructor: Int8Array, Int16Array, Int32Array, or their Uint counterparts.

If BigInt support is enabled, it also accepts the value 64 or a BigInt64Array/BigUint64Array, else it throws if passed 64 or one of those constructors.

Returns an integer-based TypedArray view of the WASM heap memory buffer associated with the given block size. If passed an integer as the first argument and unsigned is truthy then the "U" (unsigned) variant of that view is returned, else the signed variant is returned. If passed a TypedArray value, the 2nd argument is ignored. Note that Float32Array and Float64Array views are not supported by this function.

Be aware that growth of the heap may invalidate any references to this heap, so do not hold a reference longer than needed and do not use a reference after any operation which may allocate. Instead, re-fetch the reference by calling this function again, which automatically refreshes the view if needed.

Throws if passed an invalid n.