I have checked out Where to use ArrayBuffer vs typed array in JavaScript? but it doesn't describe if ArrayBuffer
is optimized by v8 or not. So say you have in there different chunks of integers or floats in the ArrayBuffer
, wondering if they will be optimized by v8 like they are a Uint8Array, etc.
Asked
Active
Viewed 240 times
-1

Lance
- 75,200
- 93
- 289
- 503
-
That doesn't make sense, TypedArrays are a **view** over an ArrayBuffer. An ArrayBuffer is just physical memory slots assigned. What optimization could there be? – Kaiido Apr 27 '18 at 01:47
-
@Kaiido see the answer, typedarrays are more optimized than arraybuffer it turns out. – Lance Apr 27 '18 at 01:56
-
No, the answer says exactly what I said: *It doesn't make sense to optimize an ArrayBuffer*, or in @jmrk words: "*I don't see what you would optimize about them"*. You clearly are missing something about ArrayBuffers and TypedArrays. Once again, ArrayBuffers are just memory slots, it's like saying the computer, I'll keep this area for myself, so don't let anyone touch it. But there is nothing to optimize here. Because once again as the answer states, "*ArrayBuffers provide no way to access their elements*". – Kaiido Apr 27 '18 at 02:03
1 Answers
3
V8 developer here. ArrayBuffers are just data containers, I don't see what you would optimize about them. What kind of optimizations would you expect for "chunks of integers or floats"?
Typed arrays are views onto ArrayBuffers; the answer to the post you linked explains that nicely. Typed arrays provide index-based access to their elements (and V8's optimizing compiler has good support for such accesses); ArrayBuffers provide no way to access their elements (so the same optimizations do not apply).

jmrk
- 34,271
- 7
- 59
- 74
-
Cool, I am new to memory stuff so I don't know much, but I was imagining the optimizations in e.g. Uint8Array are things to do with alignment/locality in memory and/or the different registers etc. like 8 bit 16 bit. Maybe there is optimizations there used by Uint8Array, I don't know what they are otherwise. If those are them then it seemed they could be applied to ArrayBuffer possibly. – Lance Apr 27 '18 at 02:08