mempool.js

1.0.4 • Public • Published

mempool.js

JavaScript true memory pooling solution.

mempool.js is powerful solution to reusable memory managment in your JavaScript application.

NPM

Installation

$ npm install mempool.js

Build and Test Scripts

cd build
$ node build.js all
cd ../test
$ node test.js

API Usage Examples

Load module:

var mempool = require('mempool.js'),
    MemoryPool = mempool.MemoryPool,
    TypedMemoryPool = mempool.TypedMemoryPool;

MemoryPool:

// custom class.
function PooledObject(value){
    this.value = value;
}
 
PooledObject.prototype.value = null;
 
// create memory pool.
PooledObject.pool = new MemoryPool(
    PooledObject.prototype, // memory pool wil store custom class objects.
    1 // pool capacity.
);
 
// create instance from pool.
var instance = PooledObject.pool.factory(1); // MemoryPool::factory() gets instance from pool and calls it's constructor.
PooledObject.pool.acquire(); // this will print error because you are trying to get instance from empty pool.
 
// release instance to pool.
PooledObject.pool.release(instance);
 
// destroy
PooledObject.pool.destroy();

TypedMemoryPool:

pool = new TypedMemoryPool(Int32Array, 1, 3);
var instance = pool.acquire();
instance[1] = 2;
pool.release(instance);
pool.destroy();

Support

Readme

Keywords

Package Sidebar

Install

npm i mempool.js

Weekly Downloads

1

Version

1.0.4

License

MIT

Last publish

Collaborators

  • psichix