1.0.4 • Published 9 years ago

mempool.js v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

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

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago