0

I have an ArrayBuffer, and I want to get two separate Uint8Array copies from it. I attempt this by using the Uint8Array constructor on the ArrayBuffer twice. The constructed array instances do not equal. Yet, when you alter one, it alters the other in the same way. How is this possible, and why would this be the case?

Unequal arrays magically influencing each other

On the other hand, if you construct new Uint8Arrays from the constructed Uint8Array, they will be functionally separated as one would expect.

Unequal arrays working properly

4

1 回答 1

2

TypedArray 内部的条目实际上存储在底层缓冲区中,如果您获取/设置数组,它会从缓冲区读取/写入/写入。如果从另一个 TypedArray 创建 TypedArray,则会复制底层缓冲区,因此不会链接数组。

 array.buffer === array1.buffer // true
 array1.buffer === array2.buffer // false
于 2019-01-25T21:02:22.080 回答