简体   繁体   English

从ArrayBuffer构造两个不相等的Uint8Array会如何相互影响?

[英]How do two unequal `Uint8Array`s influence each other when constructed from an `ArrayBuffer`?

I have an ArrayBuffer , and I want to get two separate Uint8Array copies from it. 我有一个ArrayBuffer ,我想从中获得两个单独的Uint8Array副本。 I attempt this by using the Uint8Array constructor on the ArrayBuffer twice. 我通过两次在ArrayBuffer上使用Uint8Array构造函数来尝试此操作。 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? 这怎么可能?为什么会这样呢?

不相等的数组相互影响

On the other hand, if you construct new Uint8Array s from the constructed Uint8Array , they will be functionally separated as one would expect. 在另一方面,如果你构建新Uint8Array 构建小号Uint8Array ,他们将功能分开正如人们所期望。

不相等的数组正常工作

The entries inside of a TypedArray are actually stored in the underlying buffer, if you get/set the array, it reads/writes to/from the buffer. TypedArray内部的条目实际上存储在基础缓冲区中,如果您获取/设置数组,则它会向缓冲区读取/写入缓冲区。 If you create a TypedArray from another TypedArray, the underlying buffer will be copied, and therefore the arrays will not be linked. 如果从另一个TypedArray创建一个TypedArray,则将复制基础缓冲区,因此将不会链接该数组。

 array.buffer === array1.buffer // true
 array1.buffer === array2.buffer // false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM