- Hands-On Game Development with WebAssembly
- Rick Battagline
- 364字
- 2021-06-24 13:41:13
Pointers in memory
WebAssembly's memory model piggybacks on the asm.js memory model, which uses a large typed ArrayBuffer to hold all of the raw bytes to be manipulated by the module. A JavaScript call to WebAssembly.Memory sets up the module's memory buffer in 64 KB pages.
A WebAssembly module can only access data from within this ArrayBuffer. That prevents malicious attacks from WebAssembly that create a pointer to a memory address outside the browser's sandbox. Because of this design, WebAssembly's memory model is just as safe as JavaScript.
In the next section, we will be using C++ pointers in our collider object. If you are a JavaScript developer, you may not be familiar with pointers. A pointer is a variable that holds a memory location instead of the value directly. Let's look at a little bit of code:
int VAR1 = 1;
int* POINTER = &VAR1;
In this code, we have created a VAR1 variable and given it a value of 1. In the second line, we use int* to create a pointer called POINTER. We then initialize that pointer to the address of VAR1 using the & character, which, in C++, is known as the address of operator. This operator gives us the address of the VAR1 that we declared earlier. If we then want to change VAR1, we can do so using the pointer instead of directly, as shown here:
*POINTER = 2;
printf("VAR1=%d\n", VAR1); // prints out "VAR1=2"
Putting the * in front of POINTER tells C++ to set the value in the memory address where POINTER is pointing; * when used in this way is called the dereference operator.
If you would like to learn more about pointers in C++ and how they work, the following article goes into a good deal of detail on the subject: http://www.cplusplus.com/doc/tutorial/pointers/.
In the next section, we will implement compound circle colliders for collision detection on our spaceships.
- 零點起飛學Xilinx FPG
- Windows phone 7.5 application development with F#
- Augmented Reality with Kinect
- Mastering Delphi Programming:A Complete Reference Guide
- 嵌入式技術基礎與實踐(第5版)
- 平衡掌控者:游戲數值經濟設計
- 從零開始學51單片機C語言
- Learning Game Physics with Bullet Physics and OpenGL
- 電腦軟硬件維修從入門到精通
- Spring Cloud微服務架構實戰
- 面向對象分析與設計(第3版)(修訂版)
- Intel Edison智能硬件開發指南:基于Yocto Project
- 基于Proteus仿真的51單片機應用
- Istio服務網格技術解析與實踐
- Arduino項目開發:智能生活