Skip to content
/ pools Public

Object Pooling library, for garbage-free re-use of items in Node.JS

Notifications You must be signed in to change notification settings

jldailey/pools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Object pools can help prevent pauses due to garbage collection.

Most useful in real-time applications (e.g, games) where objects are created and discarded at a high rate.

Usage

As a stand-alone pool:

{ObjectPool} = require 'pools'
pool = new ObjectPool(MyClass)
x = pool.alloc(...) # use the same arguments as in 'new MyClass(...)'
pool.free(x) # the corpse of x will be re-animated by alloc()

As a class decorator (my preferred method):

{Pooled} = require 'pools'
Pooled class MyClass
    constructor: (junk) ->
x = MyClass.alloc(...)
x.free()

If a class has a destructor method, it is called from inside free().

{Pooled} = require 'pools'
Pooled class Test
    constructor: -> @status = 'inuse'
    destructor:  -> @status = 'free'

Or, a more realistic use of a destructor would be to call free() on any children that need it.

About

Object Pooling library, for garbage-free re-use of items in Node.JS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published