Wasm Execution Stack vs Linear Memory

WebAssembly (Wasm) utilizes two distinct memory structures during runtime: the function execution stack and the linear memory. This article explains the fundamental differences between these two storage areas, detailing how the execution stack securely manages function execution and local variables while the linear memory provides a mutable, contiguous address space for application data.

The Wasm Function Execution Stack

The execution stack (often referred to as the virtual machine stack) is an implicit, managed storage area used by the WebAssembly runtime to execute instructions. WebAssembly is a stack-based virtual machine, meaning most instructions push values onto this stack or pop values off it to perform operations.

The Linear Memory

Linear memory is a contiguous, sandboxed array of raw bytes that represents the primary heap of a WebAssembly module. It is defined by the module and can grow dynamically during runtime.

Key Differences at a Glance