[英]Does Uint8Array use a shared memory buffer in Node and Browser?
如果我創建一個 2 字節的緩沖區,底層的 ArrayBuffer 有時是 8 KB。 但是,如果我創建了一個 2 字節的 Uint8Array,那么底層的 ArrayBuffer 會不會有更大的風險,或者我是否可以始終依賴它為 2 字節。
示例代碼將是new Uint8Array(2).buffer.byteLength
。
是的,您可以依靠new Uint8Array( length )
創建一個byteLength length
的ArrayBuffer 。
我們有興趣創建一個new Uint8Array( length )
是
"Uint8Array"
, NewTarget , %TypedArray.prototype% , length
)。length
)。elementSize
是表 63 中為“Uint8Array”=> 1
指定的元素大小值byteLength
為elementSize
× length
。byteLength
)。 現在,雖然這適用於Uint8Array
但並非適用於所有 TypedArray。
這里的重要部分是我的第四個項目符號,其中elementSize
是從該表中確定的,因為該值將用作最終byteLength
參數的乘數。
test( Uint8Array ); // 2 test( Uint16Array ); // 4 test( Float64Array ); // 16 function test( constructor ) { console.log( constructor.name, new constructor( 2 ).buffer.byteLength ); }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.