Class (ArrayBuffer)
Underlying data structure of the ArkTS TypedArray (Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Uint8ClampedArray, and Float32Array).
NOTE
The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
This module can be imported only to ArkTS files (with the file name extension .ets).
Decorator: @Sendable
Modules to Import
import { collections } from '@kit.ArkTS';
Properties
System capability: SystemCapability.Utils.Lang
Atomic service API: This API can be used in atomic services since API version 12.
| Name | Type | Read Only | Optional | Description |
|---|---|---|---|---|
| byteLength | number | Yes | No | Number of bytes occupied by the buffer. |
constructor
constructor(byteLength: number)
A constructor used to create an ArkTS ArrayBuffer of a given length.
System capability: SystemCapability.Utils.Lang
Atomic service API: This API can be used in atomic services since API version 12.
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| byteLength | number | Yes | Number of bytes occupied by the buffer. The maximum value is 2147483647. |
Error codes
For details about the error codes, see Universal Error Codes and Utils Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. |
| 10200012 | The ArrayBuffer's constructor cannot be directly invoked. |
Example
let arrayBuffer: collections.ArrayBuffer = new collections.ArrayBuffer(10);
console.info("byteLength: " + arrayBuffer.byteLength); // byteLength: 10
slice
slice(begin: number, end?: number): ArrayBuffer
Selects a range of elements in this ArkTS ArrayBuffer to create an ArkTS ArrayBuffer.
System capability: SystemCapability.Utils.Lang
Atomic service API: This API can be used in atomic services since API version 12.
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| begin | number | Yes | Start index of the range. If a negative number is passed in, it refers to the index of begin + arrayBuffer.byteLength. |
| end | number | No | End index of the range (exclusive). If a negative number is passed in, it refers to the index of end + arrayBuffer.byteLength. The default value is the length of the original ArkTS ArrayBuffer. |
Return value
| Type | Description |
|---|---|
| ArrayBuffer | New ArrayBuffer generated. |
Error codes
For details about the error codes, see Universal Error Codes and Utils Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. |
| 10200011 | The slice method cannot be bound. |
| 10200201 | Concurrent modification error. |
Example
let arrayBuffer: collections.ArrayBuffer = new collections.ArrayBuffer(10);
let slicedBuffer: collections.ArrayBuffer = arrayBuffer.slice(0, 4);
console.info("byteLength: " + slicedBuffer.byteLength); // byteLength: 4
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 arkts-apis-arkts-collections-Float32Array
openharmony 鸿蒙 js-apis-lightweightset
openharmony 鸿蒙 errorcode-source-obfuscation
openharmony 鸿蒙 arkts-apis-arkts-utils-ASON
openharmony 鸿蒙 arkts-apis-arkts-collections-Uint8ClampedArray