开发者

Limitations of typed arrays?

开发者 https://www.devze.com 2023-03-06 21:50 出处:网络
I\'ve done some playing around with typed arrays using Firefox 4, and have noticed some things. The size of ArrayBuffer that can be created is an integer in the range [0..2147483647]. Passing 214748

I've done some playing around with typed arrays using Firefox 4, and have noticed some things.

  • The size of ArrayBuffer that can be created is an integer in the range [0..2147483647]. Passing 2147483648 throws the same error as passing a negative number, passing 4294967296 returns an empty ArrayBuffer, and passing 4294967297 returns an ArrayBuffer with length 1. Thus I assume that the size value is interpreted as a signed 32-bit integer.

  • While Int32Array objects can only be created by defaul开发者_如何学Ct from ArrayBuffer objects whose byteLength is a multiple of four, I was surprised that new Int32Array(new ArrayBuffer(2147483644)); caused Int32Array to throw the same error I would get for passing an ArrayBuffer that isn't a multiple of four, while every other lower multiple of four did work as an ArrayBuffer size.

While the first thing I noticed is pretty normal (though somewhat wasteful that signed integers appears to have been chosen), I'm particularly curious about the second thing I noticed. Are these implementation behaviours formally defined in any specification?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号