HTML and CSS Reference
In Listing 18-5, you can see that char* pointer dereferences are converted to HEAP8 array access. The next section
shows how memory access works in general.
read from and write to contiguous blocks of binary data. An ArrayBuffer stores a sequence of contiguous bytes which
can be accessed and interpreted through ArrayBufferView objects. For example, the Int8Array object exposes the
ArrayBuffer as if it were signed 8-bit integers and Float32Array exposes the same memory as if it were IEEE 32-bit
type. For example, HEAP8, used in _strlen above, is an Int8Array through which signed 8-bit integer values are
read from and written to the program's memory. Pointers, such as the variables str and s above, are simply numeric
indices into the heap. Emscripten has ArrayBufferViews for 32-bit and 64-bit floats, as well as the full range of 8-, 16-,
and 32-bit integers, both signed and unsigned.
sprinkles | 0 throughout the function. The x | 0 expression coerces the number x into a signed integer, allowing
floating point operations to 32-bit precision floating point operations without changing the semantics of the code.
memory, so the garbage collector doesn't have to do anything. Variables are always numbers, not objects, which
into fast machine code.
What is asm.js?
has identical behavior in browsers that do not specifically support it, though it runs much faster in browsers that
recognize and optimize asm.js constructs.
optimize code dynamically during execution with so-called just-in-time (JIT) compilation. asm.js, on the other
hand, can be recognized, compiled, and optimized ahead-of-time (AOT), resulting in consistent, predictable, high
performance, which is especially important for games.
what is effectively a virtual machine bytecode? Does asm.js break the “View Source” nature of the open web? Can
native code performance really be achieved with this approach?
However, to us game developers, those discussions are somewhat academic. asm.js is real and it works well in
practice, so if you want your game on the secure, cross-browser, open platform of the Web, targeting asm.js is a great