# malloc-append

> Simple append-only alloc() implementation on top of buffers and array buffers, useful for logs.

Latest version **0.0.1** (published 2016-04-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install malloc-append
pnpm add malloc-append
yarn add malloc-append
bun add malloc-append
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2016-04-02 |
| First published | 2016-04-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Charles Pick |
| Maintainers | codemix |
| Keywords | malloc, buffer, memory-management, memory |

## Links

- npm: https://www.npmjs.com/package/malloc-append
- Repository: https://github.com/codemix/malloc-append
- Homepage: https://github.com/codemix/malloc-append#readme
- Issues: https://github.com/codemix/malloc-append/issues
- npm.io page: https://npm.io/package/malloc-append

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2016-04-02

## README

# malloc-append
An append-only memory allocator with the same interface as [malloc](https://github.com/codemix/malloc), useful for implementing append only logs. Has no `free()` but does not enforce write-once.

[![Build Status](https://travis-ci.org/codemix/malloc-append.svg?branch=master)](https://travis-ci.org/codemix/malloc-append)

## 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](https://github.com/indutny/mmap.js).

It's developed using [design by contract](https://github.com/codemix/babel-plugin-contracts), 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](https://npmjs.org/package/malloc-append).

## Usage

```js
import Allocator from "malloc-append";

const heap = new Buffer(1024 * 1024);
const allocator = new Allocator(heap); // heap could also be an ArrayBuffer
console.log(allocator.inspect());

let firstAddress = 0;
let lastAddress = 0;

for (let i = 0; i < 100; i++) {
  const address = allocator.alloc(64);
  if (firstAddress === 0) {
    firstAddress = address;
  }
  if (lastAddress !== 0) {
    // do something with the address
    heap.writeUInt32LE(address, lastAddress);
  }
}

let address = firstAddress;
for (let i = 0; i < 100; i++) {
  console.log('Reading address', address);
  address = heap.readUInt32LE(address);
}

```


## License

Published by [codemix](http://codemix.com/) under a permissive MIT License, see [LICENSE.md](./LICENSE.md).

---
_Source: https://npm.io/package/malloc-append · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
