Edge JsRT: Typed Arrays, Array Buffer and Data View

Probably the biggest change surface area-wise for JsRT in Edge relates to APIs to support typed arrays. Typed arrays are data structures that allow data exchange/protocols to be implemented more efficiently by allowing buffers to be accessed in strongly typed (i.e. efficient) ways. In particular, it allows buffers to be accessed specifically as integral values rather than the general Number type that JS supports. Obviously, these can be extremely useful for native apps hosting JS, so support for working with typed arrays is a major addition to Edge JsRT.

There are three levels of objects, which I won’t go into extreme detail on because they’re well-documented elsewhere:

  • The lowest level are ArrayBuffers, which represent the raw buffers of bytes. These can be manipulated using JsCreateArrayBuffer and JsGetArrayBufferStorage. You can’t replace the storage of an ArrayBuffer–it’s basically a buffer that Chakra allocates on your behalf.
  • The next level up is a DataView, which wraps an ArrayBuffer and lets you read and write from it in a strongly typed way. These can be manipulated using JsCreateDataView and JsGetDataViewStorage. You can call the JS methods defined on the object to do the strongly typed read/writes.
  • The top level is TypedArrays. A TypedArray wraps some portion of an ArrayBuffer and can be used as a fixed-size array of values of one particular type (i.e. an array of 5 Int32 values). These can be manipulated using JsCreateTypedArray and JsGetTypedArrayStorage. You can use the JS index operation to access the members of the TypedArray.

You should also follow me on Twitter here.

Leave a Reply

Your email address will not be published. Required fields are marked *