Arraybuffer typed arrays

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.