WebAssembly module instance (source code)

= WebAssembly module instance
{c}

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>.<WebAssembly Core Specification by the W3C WebAssembly Community Group>[Execution, Runtime Structure, Store and Module Instances]{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 <byte>0 through the first <WebAssembly module instance> leaves <byte>0 in the second at zero. Code can be reused while mutable state remains distinct.<WebAssembly Core Specification by the W3C WebAssembly Community Group>[Execution, Modules, Memory Allocation and Instantiation]{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.<WebAssembly Core Specification by the W3C WebAssembly Community Group>[Execution, Modules, Instantiation; Runtime Structure, Module Instances]{ref}