Do ArrayBuffers have a maximum length?

2019-02-23 07:07发布

I little confused here. Do ArrayBuffer allocate a new memory region for it? If so, what would be the safe maximum Blob size to put on it?

3条回答
2楼-- · 2019-02-23 07:30

I was also asking myself the same question. It seems that buffer is limited by available system memory and the ability of underlying JavaScript engine's GC to handle large amounts of memory. You can easily test it for your platform by creating large buffers in your browser's console and on the other side monitoring browser's process and overall memory footprint.

I just managed to create buffers larger than 512MB on Chrome 37. However I have 4GB of system memory so it could obviously lead to crash after more allocation. I'm not interested in finding breaking point since I'm fine with allocations up to 100MB, but you can obviously test it easily for yourself.

查看更多
Bombasti
3楼-- · 2019-02-23 07:31

what would be the safe maximum Blob size to put on it

There does not seem to be a hard limit, just whatever restrictions your platform imposes.

However, if one uses some sort of indexed access, indexes shouldn't be greater than Number.MAX_SAFE_INTEGER, because interesting bugs would happen otherwise.

Luckily, 2^53-1 bytes is around 8 petabytes so it shuoldn't be a concern unless you are doing something really weird.

查看更多
Emotional °昔
4楼-- · 2019-02-23 07:41

That only depends on your system and there doesn't seems to be a limit.

According to the specification :

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

查看更多
登录 后发表回答