Detalhes do pacote

@ain1084/array-buffer-partitioner

ain108413(MIT OR Apache-2.0)0.0.4

Partition an ArrayBuffer into multiple TypedArray views efficiently.

ArrayBuffer, SharedArrayBuffer, TypedArray, partition

readme (leia-me)

Array Buffer Partitioner

npm version CI 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 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.

Features

  • Create multiple TypedArray views from a single ArrayBuffer or SharedArrayBuffer.
  • Efficient memory partitioning without manual offset calculations.

Installation

Install the library via npm:

npm i @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

For detailed API documentation, please refer to the GitHub Pages documentation.

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.

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.

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.0.4] - 2024-11-02

Added

  • Added "type": "module" to package.json to define the package as ESM-only.
  • Added "exports" field to package.json to specify the entry point explicitly for ESM compatibility.

Changed

  • Updated clean script to rm -rf ./dist docs for consistency in paths.

[0.0.3] - 2024-10-26

Added

  • Alignment Adjustment for byteOffset: Implemented automatic alignment of each TypedArray view’s byteOffset to prevent errors during view creation.
  • README.md Update:
    • Added a note in the Overview section that byteOffset alignment is essential for preventing errors when creating TypedArray views.

Changed

  • Function Adjustment: Modified the createArrayBufferViews function to automatically align the byteOffset of each TypedArray view, preventing errors across different data types.

Fixed

  • Error Prevention: Enforced correct alignment during TypedArray view creation to resolve potential errors.

[0.0.2] - 2024-10-26

Changed

  • Updated README to replace the "Documentation" badge with a "CI" badge to reflect the status of continuous integration workflows.
  • Updated the badge URL and link to point to the correct GitHub Actions workflow.

[0.0.1] - 2024-10-26

  • Initial release