简体   繁体   English

JavaScript没有为ArrayBuffer分配所需的大小

[英]JavaScript is not allocating needed size for ArrayBuffer

I tried to run this code to allocate a ArrayBuffer: 我试图运行此代码来分配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. Chrome不会给我任何错误/警告。

This problem is not on every platform, but on several like on Galaxy S6 (Android Browser) 这个问题不是在每个平台上,而是在Galaxy S6(Android浏览器)上的几个问题上

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 http://www.ecma-international.org/ecma-262/6.0/#sec-createbytedatablock

Let db be a new Data Block value consisting of size bytes. 设db是一个由大小字节组成的新数据块值。 If it is impossible to create such a Data Block, throw a RangeError exception. 如果无法创建此类数据块,则抛出RangeError异常。

And the previous spec https://www.khronos.org/registry/typedarray/specs/latest/#5 以前的规范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. 因此,如果您的浏览器返回较小的缓冲区而不是抛出异常,则它不符合要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM