Java Reference
In-Depth Information
Typed Arrays
Typed array views are array-like objects that deal with a specific type of values such as
32-bit signed integers. They provides a means to read and write the specific type of data
to the
ArrayBuffer
. In a typed array view, all data values are of the same size. Table
7-1
contains the list of typed array views, their sizes and descriptions. The size in the table
is the size of one element of the typed array view. For example,
Int8Array
contains
elements that are 1 byte in length each. You can think of the
Int8Array
as a
byte
array
type in Java, the
Int16Array
as the
short
array type in Java, and
Int32Array
as the
int
array type in Java.
Table 7-1.
The List of Typed Array Views, Their Sizes, and Descriptions
Typed Array View
Size in Byte
Description
Int8Array
1
8-bit 2's complement signed integer
Uint8Array
1
8-bit unsigned integer
Uint8ClampedArray
1
8-bit unsigned integer (clamped)
Int16Array
2
16-bit 2's complement signed integer
Uint16Array
2
16-bit unsigned integer
Int32Array
4
32-bit 2's complement signed integer
Uint32Array
4
32-bit unsigned integer
Float32Array
4
32-bit IEEE floating point
Float64Array
8
64-bit IEEE floating point
■
a typed array is a fixed-length, dense array-like object, whereas an
Array
object is
a variable-length array that may be sparse or dense.
Tip
Let us differentiate between two array types:
Uint8Array
and
Uint8ClampedArray
.
Elements in both arrays contain 8-bit unsigned integers ranging from 0 to 255.
Uint8Array
uses modulo 256 to store values in the array whereas
Uint8ClampedArray
clamps the values between 0 and 255 (inclusive). For example, if you store 260
in a
UInt8array
, 4 is stored because 260 modulo 256 is 4. If you store 260 in a
Uint8ClampedArray
, 255 is stored because 260 is greater than 255 and the upper
limit is clamped at 255. Similarly, storing -2 stores 254 in a
Uint8Array
and 0 in a
Uint8ClampedArray
.
Each of the typed array view object defined the following two properties:
•
BYTES_PER_ELEMENT
•
name
Search WWH ::
Custom Search