Skip to content

PsichiX/mempool.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

JavaScript true memory pooling solution.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published