Resizable buffers
Resizable ArrayBuffer は作成時に maxByteLength を指定し、resize() で動的にサイズを変更できます。データの成長が予想される場合にバッファの再作成が不要になります。
概要
Resizable ArrayBuffer は作成時に maxByteLength を指定し、resize() で動的にサイズを変更できます。データの成長が予想される場合にバッファの再作成が不要になります。
対応ブラウザ
| 機能 | デスクトップ | モバイル | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 111 | 111 | 128 | 16.4 | 111 | 16.4 | |
| ビルトインオブジェクト | ||||||
ArrayBuffer.ArrayBuffer.maxByteLength option `maxByteLength` オプション | 111 | 111 | 128 | 16.4 | 111 | 16.4 |
| resizable は ArrayBuffer インスタンスのアクセサープロパティで、この配列バッファーがサイズ変更かどうかを表します。 | 111 | 111 | 128 | 16.4 | 111 | 16.4 |
| resize() は ArrayBuffer インスタンスのメソッドで、この ArrayBuffer を指定されたサイズ(バイト単位)にサイズ変更します。 | 111 | 111 | 128 | 16.4 | 111 | 16.4 |
SharedArrayBuffer.SharedArrayBuffer.maxByteLength option `maxByteLength` オプション | 111 | 111 | 128 | 16.4 | 111 | 16.4 |
| grow() は SharedArrayBuffer インスタンスのメソッドで、 SharedArrayBuffer を指定されたサイズ(バイト単位)へ伸長します。 | 111 | 111 | 128 | 16.4 | 111 | 16.4 |
| growable は SharedArrayBuffer インスタンスのアクセサープロパティで、この SharedArrayBuffer が伸長可能かどうかを返します。 | 111 | 111 | 128 | 16.4 | 111 | 16.4 |
| maxByteLength は SharedArrayBuffer インスタンスのアクセサープロパティで、この SharedArrayBuffer が伸長できる最大長(バイト単位)を返します。 | 111 | 111 | 128 | 16.4 | 111 | 16.4 |
基本構文
const buffer = new ArrayBuffer(8, { maxByteLength: 64 });
buffer.byteLength; // 8
buffer.resize(32);
buffer.byteLength; // 32 ライブデモ
Create a resizable ArrayBuffer
Allocate a resizable buffer when the option is supported.
Resize a buffer
Grow a resizable buffer and inspect the new typed-array view length.
Guard resize at runtime
Use feature detection before relying on buffer resizing helpers.
実務での使いどころ
-
Resizable buffers の活用
サイズ変更可能な ArrayBuffer と SharedArrayBuffer。maxByteLength を指定して動的にリサイズ可能。
注意点
- 古いブラウザ(IE等)では対応していない。対象ブラウザを確認すること。
アクセシビリティ
- JavaScript による動的更新時は、aria-live リージョンで変更をスクリーンリーダーに通知する。
参考リンク
Powered by web-features