JSPM

@ain1084/array-buffer-partitioner

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q44101F
  • License (MIT OR Apache-2.0)

Partition an ArrayBuffer into multiple TypedArray views efficiently.

Package Exports

  • @ain1084/array-buffer-partitioner
  • @ain1084/array-buffer-partitioner/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ain1084/array-buffer-partitioner) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@ain1084/array-buffer-partitioner

npm version Documentation License: MIT License

Partition an ArrayBuffer into multiple TypedArray views efficiently, while handling complex memory layouts and ensuring optimal alignment for better access performance.

Overview

@ain1084/array-buffer-partitioner is a utility library designed to create multiple TypedArray views on a single ArrayBuffer or SharedArrayBuffer. This can be particularly useful when dealing with various data types that need to coexist within a single buffer, without manually calculating offsets and ensuring correct alignment.

Features

  • Create multiple TypedArray views from a single ArrayBuffer or SharedArrayBuffer.
  • Efficient memory partitioning without manual offset calculations.
  • Future-proof: planned support for alignment adjustment to optimize memory access performance.

Installation

Install the library via npm:

npm install @ain1084/array-buffer-partitioner

Usage

Import the createArrayBufferViews function to partition an ArrayBuffer or SharedArrayBuffer into multiple views:

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

API

createArrayBufferViews(BufferType: { new(size: number): ArrayBuffer | SharedArrayBuffer }, config: Record<string, [TypedArrayConstructor, number]>)

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<string, [TypedArrayConstructor, number]>): An object specifying the desired views. Each key represents the name of the view, and the value is a tuple where:
    • The first element is the TypedArray 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.

Future Plans

  • Alignment Support: Future versions will include alignment support to ensure efficient access patterns, especially when working with mixed data types like Float32Array and Uint8Array. This will improve the performance of memory access and help avoid inefficient alignments.

Contributing

Contributions are welcome! If you have ideas, suggestions, or issues, please create an issue on the GitHub repository.

License

This project is licensed under the MIT OR Apache-2.0 license.