WebAssembly module instance

ID: webassembly-module-instance

A WebAssembly module instance is the runtime realization of a WebAssembly module. It collects references to the functions, memories and other entities that the WebAssembly module imports, defines or exports. The WebAssembly store contains the allocated runtime objects; a module's local indices are resolved through the corresponding WebAssembly module instance.[ref]
For example, (module (memory (export "memory") 1)) declares and exports one page of WebAssembly linear memory. Instantiate this WebAssembly module twice. Each instantiation allocates its own declared memory, so writing17 into byte0 through the first WebAssembly module instance leaves byte0 in the second at zero. Code can be reused while mutable state remains distinct.[ref]
The import case supplies a useful counterexample. If a WebAssembly module imports memory and two instantiations receive the same memory object, writes through one are visible through the other. The WebAssembly module instances are distinct but that resource is shared. Instantiation therefore links imported entities as well as allocating local definitions; it also initializes active segments and invokes the start function when one is present.[ref]

New to topics? Read the docs here!