diff --git a/term-native.ts b/term-native.ts index d81097d..6f2eafa 100644 --- a/term-native.ts +++ b/term-native.ts @@ -141,7 +141,9 @@ export async function createTermNative( CLAY_DEFAULT_MAX_ELEMENT_COUNT * MAX_FIXED_ELEMENT_WIRE_BYTES; let statePtr!: number; - let opsBuf!: number; + // opsBuf is fixed-size: attached mode allocates it exactly once here; + // standalone mode recomputes it in layout() as the state region resizes. + let opsBuf = attach ? attach.alloc(transferBytes, 4) : 0; let arena: number | undefined; let arenaCapacity = 0; @@ -150,15 +152,11 @@ export async function createTermNative( if (attach) { // Bump-allocated memory is never reclaimed: reuse the arena when // it still fits, otherwise allocate a larger one and abandon the - // old (growth-only, renderer-spec 7.7). opsBuf is fixed-size and - // allocated once. + // old (growth-only, renderer-spec 7.7). if (arena === undefined || size > arenaCapacity) { arena = attach.alloc(size); arenaCapacity = size; } - if (opsBuf === undefined) { - opsBuf = attach.alloc(transferBytes, 4); - } statePtr = ct.init(arena, lw, lh, attach.structPtr); } else { // Standalone layout is [heap: state][opsBuf]; opsBuf moves when