npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sambhav-gautam/osmemoryallocator

v1.0.53

Published

A Node.js module for custom memory management using the MeMS system, providing efficient page-based allocation and deallocation via a native addon.

Readme

MeMS: Node.js Memory Allocator

  __  __ _____ __  __  ____  
 |  \/  | ____|  \/  |/ ___| 
 | |\/| |  _| | |\/| | |___  
 |_|  |_|_|   |_|  |_|\____| 
 Memory Management System

Custom memory management for Node.js with a page-based allocation system.


osmemoryallocator

npm version npm downloads

Overview

MeMS (Memory Management System) is a Node.js module that provides a custom memory allocator implemented as a native addon. Built with node-gyp, it offers efficient page-based memory allocation and deallocation, ideal for applications requiring fine-grained control over memory.

Key Features

  • Page-Based Allocation: Allocates memory in 4KB pages for efficiency
  • Main and Sub-Chains: Organizes memory in linked lists for dynamic allocation
  • Memory Stats: Provides detailed statistics on memory usage and fragmentation
  • Cross-Platform: Supports Windows, macOS, and Linux (Node.js >= 14.0.0)
  • Native Performance: Leverages C for low-level memory operations

Prerequisites

Before installing MeMS, ensure you have the following:

  • Node.js (>= 14.0.0): Download
  • Python (3.7–3.12): Required for node-gyp builds. Download
  • Build Tools:
    • Windows: Visual Studio 2022 Build Tools with "Desktop development with C++" workload
    • macOS/Linux: gcc, make, and python3
  • node-gyp: Install globally with npm install -g node-gyp@latest

Windows Setup

winget install Python.Python.3.12
npm config set python C:\Path\To\Python312\python.exe

Install Visual Studio 2022 Build Tools with C++ workload.
For stability with Node.js 20.x:

nvm install 20
nvm use 20

Installation

Install MeMS via npm:

npm install @sambhav-gautam/osmemoryallocator

This command downloads the package and runs node-gyp rebuild to compile the native addon (mems.node).


Usage

const mems = require('@sambhav-gautam/osmemoryallocator');

// Initialize MeMS
mems.init();
console.log('MeMS initialized');

// Allocate 1000 bytes
const ptr = mems.malloc(1000);
console.log('Allocated at virtual address:', ptr);

// Get physical address
const phyPtr = mems.get(ptr);
console.log('Physical address:', phyPtr);

// Print memory stats
mems.printStats();

// Free memory
mems.free(ptr);
console.log('Memory freed');

// Clean up
mems.finish();
console.log('MeMS finished');

Example Output:

MeMS initialized
Allocated at virtual address: 1000
Physical address: <some_physical_address>
MeMS Stats:
MAIN[1000:5095] -> <P>[SVA:1000:EVA:1999] <-> <H>[SVA:2000:EVA:5095] <-> <NULL>
Page used: 1
Space unused: 3096
Main Chain Length: 1
Sub-chain Length array: 2
Memory freed
..........Successfully UnMapped the Memory without Errors .........
MeMS finished

Architecture

+----------------+    +----------------+    +----------------+
|   Main Chain   |--->| Virtual Memory |--->| Physical Pages |
+----------------+    +----------------+    +----------------+
       |                     |
       v                     v
+----------------+    +----------------+
|  Sub-Chain     |    | Address Mapping|
+----------------+    +----------------+

MeMS uses a two-level structure:

  • Main Chain: Tracks large memory blocks allocated via mmap
  • Sub-Chain: Manages allocated and free segments within main blocks

API Reference

| Function | Description | Parameters | Returns | |----------------|--------------------------------------------------|------------------|-----------------| | init() | Initializes the MeMS system | None | undefined | | malloc(size) | Allocates size bytes (aligns to 4KB) | size (number) | BigInt (vaddr) | | get(v_ptr) | Maps virtual address to physical address | v_ptr (BigInt) | BigInt (paddr) | | free(ptr) | Frees memory at given virtual address | ptr (BigInt) | undefined | | printStats() | Prints memory usage statistics | None | undefined | | finish() | Unmaps all allocated memory | None | undefined |

Notes:

  • Always call init() before other functions
  • malloc returns a BigInt representing the starting virtual address
  • free merges adjacent holes to reduce fragmentation

Testing

Run the included test script:

npm test

Test script example (test.js):

const mems = require('@sambhav-gautam/osmemoryallocator');

mems.init();
const ptr = mems.malloc(1000);
console.log('Allocated:', ptr);
mems.printStats();
mems.free(ptr);
mems.printStats();
mems.finish();

Building from Source

git clone https://github.com/Sambhav-Gautam/osmemoryallocator.git
cd osmemoryallocator
npm install
npm run build

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit changes: git commit -m "Add your feature"
  4. Push to the branch: git push origin feature/your-feature
  5. Open a pull request

See CONTRIBUTING.md for details.


License

ISC License. See LICENSE for details.


Contact