canvaskit-wasm 0.39 build 2026-04-29

MallocObj

A handle to a chunk of WASM linear memory you allocated explicitly. Returned by CK.Malloc(typedArrayCtor, length). The point: zero-copy data exchange between JavaScript and WASM. Reading or writing pixels through a MallocObj lets Skia work directly on JS-visible bytes without an intermediate heap-to-WASM copy.

Pair it with Canvas.readPixels / MakeRasterDirectSurface to build pipelines that read pixels back into JS without the per-frame copy cost.

// Allocate a 4 KB buffer of Float32s.
const m = CK.Malloc(Float32Array, 1024);
const view = m.toTypedArray();    // a Float32Array view backed by the WASM memory
view[0] = 42;
// ... use m / view ...
CK.Free(m);                       // release when done

Fields

FieldTypeNotes
byteOffsetnumberPointer into WASM linear memory. Pass to native APIs that take a raw pointer.
lengthnumberElement count.
toTypedArray()TypedArrayJS-side view into the WASM memory. The view stays valid until CK.Free.
subarray(begin, end)TypedArraySub-view sharing the underlying buffer.

Lifetime

Allocate with CK.Malloc(typedArrayCtor, length). Free explicitly with CK.Free(mallocObj) — these aren't GC'd. Forgetting CK.Free leaks WASM memory.

See also