backing
Persistent storage for typed arrays / buffers.

What?
Provides a virtual address space for large segments of memory via ArrayBuffers, and operations for alloc()
ing and free()
ing
within the address space, optionally via a simple reference counting garbage collector.
These large segments of data can optionally be automatically persisted to disk, (and shared with other processes!) via mmap.
For related work which builds on top of this see reign - a persistent, typed objects system.
Installation
Install via npm.
npm install backing
Usage
import Backing from "backing";
const store = new Backing({
name: "demo",
arenaSize: 16 * 1024 * 1024,
arenaSource: {
type: 'mmap',
dirname: __dirname + '/data',
lifetime: 2
}
});
async function run () {
await store.init();
const address = store.alloc(64);
store.setInt32(address, 123);
console.log(store.getInt32(address));
store.free(address);
const address2 = store.gc.alloc(64);
store.setFloat64(address2, 456.789);
console.log(store.gc.sizeOf(address2));
console.log(store.getFloat64(address2));
store.gc.ref(address2);
store.gc.cycle();
store.gc.unref(address2);
let freed = store.gc.cycle();
console.log(freed);
freed = store.gc.cycle();
console.log(freed);
}
run();
License
Published by codemix under a permissive MIT License, see LICENSE.md.