array-allocator
v1.2.0
Published
Easy reusable arrays
Downloads
7
Readme
Easy Reusable Arrays in JavaScript
array-allocator is useful when you need to create and reuse temporary numeric arrays.
Usage
Allocate and free numeric arrays
Allocate an arr array with length of 42 elements.
When you call free(arr), it only marks the array as "free".
If you later request an array with the same length, array-allocator will return the same reference.
import {alloc, free} from "array-allocator";
const arr: number[] = alloc(42);
console.log(arr.length); // => 42
// ...
free(arr);
const brr: number[] = alloc(42);
console.log(arr === brr); // => true
// ...
free(brr);Release allocated resources
import {alloc, free, compact} from "array-allocator";
const arr: number[] = alloc(42);
free(arr);
// ...
compact();Exported methods
/**
* Allocates a resource
*/
function alloc(arrLen: number): number[]
/**
* Marks an allocated resource "free"
*/
function free(arrRef: number[]): void
/**
* Deallocated freed resources
*/
function compact(): void