Skip to content

Commit

Permalink
docs: add sections on memory, tables, and ecosystem to WebAssembly in…
Browse files Browse the repository at this point in the history
…troduction
  • Loading branch information
Pradumnasaraf committed Dec 26, 2024
1 parent 193bcb3 commit 56e3327
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/webassembly/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,31 @@ Data Types - References:

Instructions and data types work together to perform specific tasks. For example, to add two numbers, we use the `i32.add` instruction. It's a binary instruction that tells the WebAssembly engine to add two 32-bit integers. Here, `i32` is the data type that specifies the kind of data we are working with, and `add` is the instruction that tells the engine what action to perform.

## Memory and Tables

### Why we need Memory and Tables?

Think it more like a building a city (which is a program) the buildings are the data and they plot of land that's the memory. The roads are the tables. And the city services are the functions and those functions needs a directory to be organized for that we have tables. Without memory and tables, the city (program) can't function properly and can be chaotic.

![memory and tables](https://github.com/user-attachments/assets/f8071a47-0a88-4919-a796-ae7e9d7ec816)

### Memory

When we so something like add two number say 3 and 5, these number are stored in what's called WebAssembly memory. After the addition it stores the result back in the memory, that is the result 8. And by doing this it make isolated from the rest of the computer's memory making it secure and if something goes wrong it won't affect the rest of the computer.

Memory can grow as needed. It can be accessed by the WebAssembly module as well as the JavaScript code.

![memory](https://github.com/user-attachments/assets/772d45c9-639a-4075-8ced-d6cb8d0762b8)

### Tables

They are more like directories and lookup tables. They don't store actual data but store references to functions. For example, if we have a function that calculates the square of a number, we can store a reference to that function in a table. When we need to calculate the square of a number, we can look up the function in the table and call it.

Not only it stores references to functions, it can store references global variables, objects,

![tables](https://github.com/user-attachments/assets/e5578a4b-5cc2-46b8-843b-d2b315bfcf5b)


## Tools and Ecosystem


0 comments on commit 56e3327

Please sign in to comment.