Skip to content

1000ch/memorypool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MemoryPool

JavaScript Memory Pool implementation

Build Status NPM version Dependency Status devDependency Status

Install

$ npm install memorypool

Usage

const MemoryPool = require('memorypool');
const arrayPool = new MemoryPool(Array);
const stringPool = new MemoryPool(String);

let array1 = arrayPool.allocate();
let array2 = arrayPool.allocate();
arrayPool.free(array1);
arrayPool.free(array2);
let string1 = stringPool.allocate();
stringPool.free(string1);

// reuse Array instance from array pool
let array3 = arrayPool.allocate();
// reuse String instance from string pool
let string2 = stringPool.allocate();

API

new MemoryPool(type)

Constructor to create new instance of object pool.

let pool = new MemoryPool(String);

MemoryPool#allocate()

Returns an instance of type passed on constructor.

let instance = pool.allocate();

MemoryPool#free(object: type)

Returns an object to object pool.

pool.free(instance);

MemoryPool#collect()

Clear references to collect memory by GC.

pool.collect();

License

MIT: http://1000ch.mit-license.org

About

JavaScript Memory Pool implementation

Resources

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published