cav*_*ila 5 javascript filereader arraybuffer
我在这里有点困惑.ArrayBuffer为它分配一个新的内存区域吗?如果是这样,那么安全的最大Blob大小是什么?
End*_*ess 10
我自己需要知道这一点,所以我编写了一个脚本,可以使用二分搜索以最快的方式搜索最大值。(这是通过(这是对/sf/answers/2515919241/,但适用于 bigint)
\n/**\n * Binary search for a max value without knowing the exact value, only that it\n * can be under or over It dose not test every number but instead looks for\n * 1,2,4,8,16,32,64,128,96,95 to figure out that you thought about #96 from \n * 0-infinity\n *\n * @example findFirstPositive(x => matchMedia(`(max-resolution: ${x}dpi)`).matches)\n * @author Jimmy W\xc3\xa4rting\n * @see {@link https://stackoverflow.com/a/72124984/1008999}\n * @param {function} f The function to run the test on (should return truthy or falsy values)\n * @param {bigint} [b=1] Where to start looking from\n * @param {function} d privately used to calculate the next value to test\n * @returns {bigint} Intenger\n */\nfunction findFirstPositive (f,b=1n,d=(e,g,c)=>g<e?-1:0<f(c=e+g>>1n)?c==e||0>=f(c-1n)?c:d(e,c-1n):d(c+1n,g)) {\n for (;0>=f(b);b<<=1n);return d(b>>1n,b)-1n\n}\n\nconst tries = []\nconst maxSize = findFirstPositive(x => {\n tries.push(Number(x).toLocaleString())\n try { new ArrayBuffer(Number(x)); return false } catch { return true }\n})\nconsole.log(\'found it in\', tries.length, \'attempts\')\nconsole.log(Number(maxSize))\nconsole.log(tries)
Run Code Online (Sandbox Code Playgroud)\r\n以下是我的 MacOS 上的一些结果
\n放置在其上的安全最大 Blob 大小是多少
似乎没有硬性限制,只是您的平台施加了任何限制。
但是,如果使用某种索引访问,索引不应大于Number.MAX_SAFE_INTEGER,否则会发生有趣的错误。
幸运的是,2^53-1 字节约为 8 PB,因此除非您正在做一些非常奇怪的事情,否则不必担心。
归档时间: |
|
查看次数: |
5048 次 |
最近记录: |