Typed arrays are an interface for JavaScript to manipulate binary data
Since the advent of the WEBGL project, the so-called WebGL refers to the interface between the browser and the video card, in order to satisfy the large and real-time data exchange between JavaScript and the video card, the communication between them must be binary, not the traditional text format. For example, it is time-consuming to pass a 32-bit integer in text format, and both JavaScript scripts and graphics cards are formatted for conversion. At this point, if there is a mechanism, like the C language, directly manipulate the byte, and then the 4-byte 32-bit integer, in binary form into the video card intact, the performance of the script will be greatly improved. Typed arrays are born in this context. It is like an array of C languages, allowing the developer to manipulate memory directly in the form of an array subscript. With typed arrays, JavaScript's binary data processing capabilities are enhanced, and interfaces can be fully binary data-based.
Typed arrays are built on the basis of the Arraybuffer object. Its role is to allocate a contiguous area of memory that can hold data.
Let buffer =new ArrayBuffer (+) // generate a 32-byte memory area / / allocated memory area byte length (+) // determine if the creation was successful if (buffer.bytelength == =// Success } Else {// failed }
Slice method: A new Arraybuffer object is generated by copying a portion of the memory area. In addition to this method, the Arraybuffer object does not provide any method of directly reading and writing memory, only allowing the view to be built above it, and then reading and writing through the view
var New ArrayBuffer (8)var newbuffer = Buffer.slice (0,3)
Arraybuffer typed arrays