Lawrence Douglas Lawrence Douglas - 4 months ago 11
Node.js Question

Is it possible to create an unsafe array buffer in the browser?

In

node.js
, the
Buffer
implements a
Uint8Array
, which is also available in the browser.

There is a method in
node.js
to create an unsafe buffer, where the bytes are not pre-initialized to 0. This is much faster to allocate since you don't have to zero out all the entries, and as long as you later fill everything, it is safe.

Is there anything like this in the client-side browser Javascript? For speed reasons when creating a large amount of arrays which I immediately fill with values, I'm looking for a way to unsafely allocate these buffers.

Answer

No, this is not possible. According to the specification, all typed arrays are initialized to 0s.