“This is the sixth day of my participation in the November Gwen Challenge.The final text challenge in 2021” |
---|
The biggest benefit of typed arrays is that they are more efficient because the browser knows the data types in the array in advance. Js Array in the internal implementation is of linked list, can increase dynamic reduce elements, but many elements, the performance will be poor, is a continuous memory area Array typed management, knew the starting position of the memory, can be offset by starting position + N * (an addition a multiplication operation) access to the NTH element, For Array, you need to go through the linked list one by one.
Typed arrays split the implementation into buffers and views. An ArrayBuffer describes a chunk of binary data in memory. The buffer has no format and provides no mechanism to access its contents. To access the memory contained in the cache object, you need to use views. Views can convert binary data into actually typed arrays. A buffer can be provided to multiple views for reading. Different views have different memory lengths and read data in different formats. Buffering and views work as shown below:
The various typed arrays used by WebGL
An array type | Number of bytes per element | describe |
---|---|---|
Int8Array | 1 | An 8-bit integer (signed char) |
UInt8Array | 1 | An 8-bit unsigned char |
Int16Array | 2 | 16 bit integer (signed short) |
UInt16Array | 2 | 16-bit unsigned char |
Int32Array | 4 | 32-bit integer (signed int) |
UInt32Array | 4 | 32-bit unsigned char |
Float32Array | 4 | Single-precision 32-bit float |
Float64Array | 8 | 64-bit floating-point number (double) |
Methods, properties, and constants of typed arrays
Methods, properties, and constants | describe |
---|---|
get(index) | Gets the index element value |
set(inex,value) | Set the value of the index element to value |
set(array,offset) | The length of the data is filled with values from array starting at offset |
length | Array length |
BYTES_PER_ELEMENT | The number of bytes per element in an array |
Typed arrays do not support push() and pop() methods
The only way to create typed arrays is to use the new operator
var vertices = new Float32Array([
0.0.0.5, -0.5, -0.5.0.5, -0.5
])
Copy the code