Mark As Completed Discussion

To create a WebAssembly module, we must first have some C++ code that we wish to utilize within our web application. Let's take as an example a simple C++ function that sums two integers. This function could potentially be part of a much larger and complex system, for instance, the performance evaluation system of a fantasy basketball platform.

Unlike JavaScript, which executes within the browser, C++ code must undergo a compilation process to transform it into a format understandable by the computer. Our simple C++ code is written in high-level language syntax that's easy for humans to understand. However, computers require a low-level language for execution, and we use a C++ compiler to translate our high-level code into machine code. With WebAssembly, we perform a similar process, but instead of creating machine code, we compile our C++ code into WebAssembly, or WASM, modules.

Now, how does this apply to a web application? Consider our fantasy basketball platform, where real-time calculations and large data handling can be a regular operation. Utilizing C++ code to perform some of these heavy operations could bring significant performance improvements due to the efficient low-level operations that C++ offers. These software modules, initially written in C++, can efficiently manage these data-intensive tasks when compiled into WASM modules.

Take a look at the simple C++ function in the code field. It sums two integers and outputs the result. The process to compile this function into a WASM module will be explored in the following screens.

CPP
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment