Limitations of typed arrays?
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]
. Passing2147483648
throws the same error as passing a negative number, passing4294967296
returns an emptyArrayBuffer
, and passing4294967297
returns anArrayBuffer
with length1
. 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 fromArrayBuffer
objects whosebyteLength
is a multiple of four, I was surprised thatnew Int32Array(new ArrayBuffer(2147483644));
causedInt32Array
to throw the same error I would get for passing anArrayBuffer
that isn't a multiple of four, while every other lower multiple of four did work as anArrayBuffer
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?
精彩评论