New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
W3C HTML5 KIG-Typed Arrays
1. Typed Arrays
Binary Data in the Browser
2012.09.19, 동국대 멀티미디어공학과 이창환
2. Contents
Introduction
Basics of using Typed Arrays
Browser APIs that use Typed Arrays
Third-party libraries
History of Typed Arrays
Design considerations
References
2
3. Introduction
The need to have an efficient way to handle binary data in WebGL.
A slab of memory with a typed view into it
Like how arrays work in C.
The JavaScript engine can pass the memory directly to native libraries
Better than JavaScript arrays for passing data to WebGL and other APIs dealing with
binary data.
Typed array views
Single-type arrays to a segment of an ArrayBuffer.
Views for all the usual numeric types
Float32Array, Float64Array, Int32Array and Uint8Array.
Special view Uint8ClampedArray
The pixel array type in Canvas's ImageData
DataView
Handling heterogeneous data.
A get/set API to read and write arbitrary data types at arbitrary byte offsets.
Reading and writing file headers and other such struct-like data.
3
10. A Discussion of Endianness
Endianness, or byte order
big-endian: the most significant byte first
little-endian: the least significant byte first.
10
11. Browser APIs that use Typed Arrays
WebGL
Canvas 2D
XMLHttpRequest2
File APIs
Transferable objects
Media Source API
Binary WebSockets
11
13. History of Typed Arrays
Start in the early implementation stage of WebGL
JavaScript arrays Native array
Allocate a native array
Fill it by walking over the JavaScript array
Cast every JavaScript object in the array to the required native type.
Mozilla's Vladimir Vukicevic
CanvasFloatArray: a C-style float array with a JavaScript interface
Renamed WebGLFloatArray
Renamed Float32Array
split into a backing ArrayBuffer and the typed Float32Array-view to
access the buffer.
Types were added for other integer and floating-point sizes and
signed/unsigned variants.
13
14. Design considerations
Design of Typed Arrays
Need to efficiently pass binary data to native libraries.
The typed array views operate upon aligned data in the host
CPU’s native endianness.
DataView
Designed for file and network I/O
The design split
in-memory data assembly (using the typed array views)
I/O (using DataView)
Modern JavaScript engines
Optimize the typed array views heavily
Achieve high performance on numerical operations
14