Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript is not allocating needed size for ArrayBuffer

I tried to run this code to allocate a ArrayBuffer:

var data = new ArrayBuffer(336000000);
console.log(data.byteLength); // outputs 125829120

Does anyone know why the number if bytes is not allocated? Chrome don't give me any errors / warnings.

This problem is not on every platform, but on several like on Galaxy S6 (Android Browser)

like image 912
Fredrik Anfinsen Avatar asked May 09 '26 19:05

Fredrik Anfinsen


1 Answers

You're trying to allocate more memory than is available. However, according to the spec, this should raise an exception rather than returning you a smaller buffer:

http://www.ecma-international.org/ecma-262/6.0/#sec-createbytedatablock

Let db be a new Data Block value consisting of size bytes. If it is impossible to create such a Data Block, throw a RangeError exception.

And the previous spec https://www.khronos.org/registry/typedarray/specs/latest/#5

If the requested number of bytes could not be allocated an exception is raised

So if your browser is returning a smaller buffer rather than throwing an exception, it's non-compliant.

like image 146
CupawnTae Avatar answered May 12 '26 08:05

CupawnTae



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!