Partition an ArrayBuffer into multiple TypedArray views efficiently.
npm install @ain1084/array-buffer-partitioner



Partition an ArrayBuffer into multiple TypedArray views efficiently, while handling complex memory layouts and ensuring optimal alignment for better access performance.
@ain1084/array-buffer-partitioner is a utility library for creating multiple TypedArray views on a single ArrayBuffer or SharedArrayBuffer. This allows various data types to be efficiently placed within a single buffer. The library automatically adjusts each TypedArray’s byteOffset to prevent errors that can occur during view creation.
- Create multiple TypedArray views from a single ArrayBuffer or SharedArrayBuffer.
- Efficient memory partitioning without manual offset calculations.
Install the library via npm:
``sh`
npm i @ain1084/array-buffer-partitioner
Import the createArrayBufferViews function to partition an ArrayBuffer or SharedArrayBuffer into multiple views:
`typescript
import { createArrayBufferViews } from '@ain1084/array-buffer-partitioner';
const views = createArrayBufferViews(ArrayBuffer, {
data: [Float32Array, 1024],
index: [Uint32Array, 1],
flag: [Uint8Array, 1]
});
console.log(views.data.length); // 1024
console.log(views.data.byteOffset); // 0
console.log(views.index.length); // 1
console.log(views.flag.length); // 1
console.log(views.flag.byteOffset); // 4100
console.log(views.data.buffer.byteLength); // 4104
`
For detailed API documentation, please refer to the GitHub Pages documentation.
Creates multiple TypedArray views on a single ArrayBuffer or SharedArrayBuffer.
#### Parameters
- BufferType ({ new(size: number): ArrayBuffer | SharedArrayBuffer }): The constructor for the buffer, either ArrayBuffer or SharedArrayBuffer.config
- (Record): An object specifying the desired views. Each key represents the name of the view, and the value is a tuple where:TypedArray
- The first element is the class name (e.g., Float32Array, Uint32Array`).
- The second element is the number of elements for that view.
#### Returns
An object containing the views, with each key corresponding to the provided configuration.
Contributions are welcome! If you have ideas, suggestions, or issues, please create an issue on the GitHub repository.
This project is licensed under the MIT OR Apache-2.0 license.