malloc-append
An append-only memory allocator with the same interface as malloc, useful for implementing append only logs. Has no free()
but does not enforce write-once.
What?
It lets you allocate a large, contiguous slab of memory up front and then alloc()
within that buffer.
It is mostly useful in conjunction with things like mmap.js.
It's developed using design by contract, so you might find the library's own code style a bit unusual, but it doesn't affect usage or performance.
Installation
Install via npm.
Usage
; const heap = 1024 * 1024;const allocator = heap; // heap could also be an ArrayBufferconsole; let firstAddress = 0;let lastAddress = 0; for let i = 0; i < 100; i++ const address = allocator; if firstAddress === 0 firstAddress = address; if lastAddress !== 0 // do something with the address heap; let address = firstAddress;for let i = 0; i < 100; i++ console; address = heap;
License
Published by codemix under a permissive MIT License, see LICENSE.md.