4 ms·
Typed Arrays in ECMAScript 6
- rauschma 11y agoTyped Arrays are not the most exciting part of ECMAScript 6, but it is still good that they are part of the language now (vs. only a browser API). What surprised me while researching the post was how many browser APIs support Typed Arrays for binary data: File API, XMLHttpRequest, Fetch API, Canvas, WebSockets, WebGL, Web Audio API, and others. (Disclaimer: I’m the author of the blog post.)
- aeflash 11y agoAre typed arrays stored outside of the JS heap? For example, in node.js you can use Buffers to get around V8's 1.8GB JS heap limit -- are typed arrays similar? Does the ES6 spec specify whether typed arrays should be stored separately from the JS heap, or is that an implementation detail?
- rauschma 11y agoYes, that is left unspecified in the spec: * http://www.ecma-international.org/ecma-262/6.0/#sec-allocatearraybuffer http://www.ecma-international.org/ecma-262/6.0/#sec-allocate... (relevant: step 4, CreateByteDataBlock())
- ant6n 11y agoI use typed arrays in Python when I need to store a lot of data in memory, and the overhead of objects would be too large (for example I built a little library that can load a country's worth of openstreetmap data). What I really miss is typed dictionaries (int -> int).
- rauschma 11y agoI don’t think there’ll ever be typed dictionaries (which are a fairly high-level data structure). There is, however, a proposal for typed objects: https://github.com/dslomov/typed-objects-es7 https://github.com/dslomov/typed-objects-es7
- ant6n 11y agoWell, one could build a typed object-array library using typed arrays (i.e. use one typed array for every member). This actually gives me an idea... :P But you wouldn't want to rebuild a dict using integer arrays, that would be pretty slow.