Java Reference
In-Depth Information
The BYTES_PER_ELEMENT property contains the size of the elements of the types array
in bytes. Its value for a view type is the same as in the “Size in Bytes” column in Table 0-1.
The name property contains a string that is the name of the view and it is the same as the
“Typed array View” column in the table. For example, Int16Array.BYTES_PR_ELEMNET is 2
and Int16Array.name is "Int16Array" .
All typed array views provide four constructors. The following are four constructors
for Int8Array . You can replace the name Int8Array with the name of other typed array
views to get their constructors:
Int8Array(arrayBuffer, byteOffset, elementCount)
Int8Array(length)
Int8Array(typedArray)
Int8Array(arrayObject)
The first constructor creates a typed array view from an ArrayBuffer . You can create
a full or a partial view of the specified ArrayBuffer . If byteOffset and elementCount are
unspecified, it creates a full view of the ArrayBuffer. byteOffset is the byte offset in the
buffer from beginning and the elementCount is the number of elements of the array that
will occupy the buffer.
The second constructor takes the length of the typed array an argument and creates
an ArrayBuffer of the appropriate size and returns a view of the full ArrayBuffer .
The third and fourth constructors let you create a typed array from another typed
array and an Array object; the contents of the new typed array are initialized from the
contents of the specified array. A new ArrayBuffer of the appropriate size to hold the
copied contents is created.
The following code shows how to create Int8Array objects (arrays of bytes) using
different constructors:
// Create an ArrayBuffer of 8 bytes
var buffer = new ArrayBuffer(8);
// Create an Int8Array that is a full view of buffer
var fullView = new Int8Array(buffer);
// Create an Int8Array that is the first half view of buffer
var firstHalfView = new Int8Array(buffer, 0, 4);
// Create an Int8Array that is the copy of the firstHalfView array
var copiedView = new Int8Array(firstHalfView);
// Create an Int8Array using elements from an Array object
var ids = new Int8Array([10, 20, 30]);
Search WWH ::




Custom Search