WasmGPU.frameArena¶
Summary¶
WasmGPU.frameArena exposes the global transient allocator inside WasmGPU's built-in WebAssembly driver memory.
Use it for scratch pointers whose lifetime should end with the current frame or render pass.
WasmGPU.run() resets the frame arena once per animation frame, and standalone WasmGPU.render() calls reset it before rendering when the engine is not already inside run().
Syntax¶
WasmGPU.frameArena: FrameArena
const frameArena = wgpu.frameArena;
import { frameArena } from "wasmgpu";
Parameters¶
This accessor does not take parameters.
Returns¶
FrameArena - Frame allocator interface with init, alloc, reset, and stats methods.
Type Details¶
type FrameArena = {
init(capBytes?: number): number;
reset(): void;
alloc(bytes: number, align?: number): number;
allocF32(len: number): number;
epoch(): number;
usedBytes(): number;
capBytes(): number;
};
Notes¶
alloc()andallocF32()return raw Wasm pointers. Usewgpu.driver.view(...)to read or write those regions.- If you want epoch-checked typed slices instead of raw pointers, use
wgpu.driver.frame.allocF32(),allocU32(),allocI32(), orallocU8(). - Do not retain frame-arena pointers, typed-array views, or frame
WasmSliceobjects acrossframeArena.reset(), across frames insideWasmGPU.run(), or across standaloneWasmGPU.render()calls.
Example¶
const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);
const ptr = wgpu.frameArena.allocF32(4);
const values = wgpu.driver.view(Float32Array, ptr, 4);
values.set([1, 2, 3, 4]);
console.log(values[0], wgpu.frameArena.usedBytes(), wgpu.frameArena.capBytes());
wgpu.frameArena.reset();