0PricingLogin
WebAssembly (WASM) for High Performance Apps · Lesson

Passing Complex Data Structures

Learn strategies for efficiently transferring strings, arrays, and custom objects between WASM and JavaScript.

Complex Data in WASM

When building high-performance applications with WebAssembly (WASM), you often need to exchange more than just simple numbers between your WASM module and JavaScript.

  • How do you pass a string?
  • What about an array of numbers?
  • Or even a custom object structure?

This lesson explores strategies for efficiently handling these complex data types.

WASM's Linear Memory

The key to passing complex data lies in understanding WASM's linear memory. This is a contiguous block of memory (like a large array of bytes) that is shared between your WASM module and the JavaScript environment.

WASM functions can only return numbers. So, instead of passing the entire data, we pass a pointer (a memory address, which is just a number!) to where the data resides in this shared memory.

All lessons in this course

  1. Passing Complex Data Structures
  2. WASM Memory Model & Management
  3. Shared Memory & Atomics
  4. Growing & Managing Linear Memory
← Back to WebAssembly (WASM) for High Performance Apps