Javascript类型的最大大小? [英] Javascript maximum size for types?

查看:236
本文介绍了Javascript类型的最大大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看javascript类型我试图找出一些数据类型的最大存储大小。例如,我设置了一个快速递归算法来增加var大小,直到浏览器崩溃,最终在接近128mb(或者也许是256)的字符串现有版本的chrome。



我一直在做这个痛苦的方式,因为我找不到任何规格,但不断的浏览器崩溃使这是一个痛苦的试验(尝试catch似乎无用的某些原因与这个特定的问题)。



我正在寻找其他类型的最大存储大小的信息(数组,对象,函数,字符串,数字,bools ...)

EMCA-262第8.4节对此不清楚


字符串的长度是数字的元素(即,16位值)。空字符串的长度为零,因此不包含任何元素。


...所以也许这是需要被识别为实现在浏览器中?



但是ECMA告诉我们数字,例如


数字类型具有精确的18437736874454810627(即2 ^ 64-2 ^ 53 + 3)个值,表示在IEEE二进制浮点算术标准中规定的双精度64位格式IEEE 754值,除了IEEE标准的9007199254740990(即2 ^ 53-2)个不同的非数字值在ECMAScript中表示为单个特殊NaN值。


但是我没有看到任何对象。



我期望在浏览器中使用什么?



我可以在单个脚本中分配多少内存?

$ b $如上所述,规范说明除数字之外的类型的任何大小限制/要求



因此,这完全取决于实现。



Chrome对字符串的限制似乎被硬编码在大约512mb(而不是32bit)。


这样就限制了最大
可能的分配请求在32位版本的2 ^ 27-1。最大扁平字符串
的长度是〜2 ^ 28(512MB空格),最大字符串长度是2 ^ 29-1,所以这两个限制都不能捕获这个问题(我们会抛出Out-


请参阅:http://code.google.com/p/v8/issues/detail?id=362#c9



对于其他浏览器,这需要一些研究,例如查看Firefox的代码。但我怀疑我们可以做同样的IE / Opera。


Looking into javascript types I'm trying to find out what the maximum storage size for some data types are. For instance, I set up a quick recursive algo to increase var size till the browser crashes, which ends up being somewhere close to 128mb (or maybe it's 256) for strings on my existing version of chrome.

I've been doing it the painful way because I couldn't find any specs on this, but constant browser crashes make this a painful trial (try catch seems useless for some reason with this particular issue).

I'm looking for information about maximum storage size for the other types also (array, object, functions, strings, numbers, bools...)

EMCA-262 section 8.4 is vague on this

The length of a String is the number of elements (i.e., 16-bit values) within it. The empty String has length zero and therefore contains no elements.

...so perhaps this is something that needs to be identified as implemented in browsers?

ECMA does however tell us about numbers, for example,

The Number type has exactly 18437736874454810627 (that is, 2^64−2^53+3) values, representing the double-precision 64-bit format IEEE 754 values as specified in the IEEE Standard for Binary Floating-Point Arithmetic, except that the 9007199254740990 (that is, 2^53−2) distinct "Not-a-Number" values of the IEEE Standard are represented in ECMAScript as a single special NaN value.

But then I don't see anything about objects.

What can I expect for use in browsers? Is there any code-base out there that helps manage very large objects and strings?

How much memory can I allocate in a single script?

解决方案

As you already stated, the specification does not state any size limits / requirements for types besides Number.

So this is definitally left to the implementation.

For example, Chrome's limit on strings seems to be hard coded at around 512mb (and less on 32bit).

This puts a limit on the maximally possible allocation request in 32-bit versions of 2^27-1. The maximal flat string length is ~2^28 (512MB space), and the maximal string length is 2^29-1, so neither of these limits catch the problem (we would throw an Out-Of-Memory exception instead if they did).

See: http://code.google.com/p/v8/issues/detail?id=362#c9

As far as the other browsers go, this would need some research e.g. looking into Firefox's code. But I doubt we can do the same for IE / Opera.

这篇关于Javascript类型的最大大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆