Game Development Reference
In-Depth Information
// Create a typed array with 4 elements, each
32 bits long
var i32viewA = new Int32Array(4);
// Create the same typed array, but using an
explicit ArrayBuffer first
var buffer = new ArrayBuffer(16)
var i32viewB = new Int32Array(buffer)
While the two typed arrays above, refer to two separate and unique memory loca-
tions, they are identical at run time, and cannot be told apart (unless the actual ar-
rays hold different values, of course); the point here being that an array buffer view
constructor can take an ArrayBuffer , or simply an integer . If you use an Ar-
rayBuffer , all of the restrictions just mentioned apply, and must be handled with
care. If you only supply an integer , the browser will create an array buffer of the
appropriate size for you automatically. In practice, there are rare occasions and reas-
ons, where you'd want to manually create an array buffer separately. It is noteworthy,
however, that it is totally legal to create multiple array buffer views for the same array
buffer, even if each view is of a different data type. Remember that, since the buffer
refers to a single memory location, so all views bound to the same buffer are sharing
that memory space.
Search WWH ::




Custom Search