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 🙏

© 2026 – Pkg Stats / Ryan Hefner

memory-pool

v1.2.0

Published

Fast implementation of memory pool in JavaScript.

Readme

memory-pool

Build Status Dependency Status devDependency Status

Introduction

This library implements a very fast memory pool. It can be used in game engines for the purpose of storing multiple objects of the same type.

Here are benchmark results collected on Google Chrome 50.0.2661.102 m (64-bit) running on Windows 10 and Intel [email protected]. Source code of the benchmark is available here:

Benchmark results

Benchmark results

Benchmark results

Note on the last benchmark the memory graph. First half presents graph of memory usage for MemoryLoop while second contains 'new' keyword.

Also, the cost of Garbage Collection is now more visible than in any other of the benchmarks. While 'new' keyword performance dropped twice, Memory Pool retained most of it's speed - the difference is just around 2ms which might be caused by external system factors.

Installation

npm install memory-pool

Usage - web browser

Before you start using this library simply include the node_modules/memory-pool/dist/memory-pool.js file on your website. It's recommended to include this file in your assets pipeline and concatenate it with the rest of your javascript files.

Usage - Node.js

To include the memory pool within Node.js app simply load the module.

var MemoryPool = require("memory-pool");

Creating memory pool

The following example creates a homogeneous memory pool. objectFactory function creates a new EMPTY instance of the object to store in the memory. Memory gets filled with the specified amount of elements of the same type. In this example it's 1024 objects of a type foo. Library adds a custom field to the class '__memoryAddress__' which is used for performance reasons. Make sure your objects are not overwriting that field or MemoryPool will break.

function foo()
{
    this.doSomething = function ()
    {
        console.log("I'm doing something.");
    };
}

function objectFactory()
{
    return new foo();
}

var size = 1024;
var memoryPool = new MemoryPool(size, objectFactory);

Allocating and de-allocating objects

This example presents how to allocate and de-allocate objects using the library.

function foo()
{
    this.doSomething = function ()
    {
        console.log("I'm doing something.");
    };
}

function objectFactory()
{
    return new foo();
}

var size = 1024;
var memoryPool = new MemoryPool(size, objectFactory);

// Allocating new object
var bar = memoryPool.allocate(); // This returns the object of a type 'foo'

// Doing something with your object
bar.doSomething();

// free the object and return it to the pool
memoryPool.free(bar);

Dynamic memory pool size expansion

This memory pool supports dynamic resizing. In case you allocate more objects than the number predicted in the constructor, the library will automatically expand the size by default amount of 256 elements. You can override that value using third constructor argument.

var size = 1;
var growBy = 2;
var memoryPool = new MemoryPool(size, objectFactory, growBy);

// Allocate first object. Size won't change.
var first = memoryPool.allocate();

// Allocate second object. Memory pool will expand by 2.
var second = memoryPool.allocate();

// Allocate third object. Memory pool size won't change - now it can accommodate 3 objects.
var third = memoryPool.allocate();

// Remember to ALWAYS release the objects
// otherwise you'll end up with memory leaks
memoryPool.free(first);
memoryPool.free(third);
memoryPool.free(second);

Support

Report a problem or improvement