Haxe ObjectPooling
package;
import nme.errors.Error;
class ObjectPool<T>
{
private var pool:Array<T>;
private var counter:Int;
public function new(_pooledType:Class<T>,len:Int)
{
pool = new Array();
counter = len;
var i:Int = len;
while(--i > -1)
{
pool[i] = Type.createInstance(_pooledType,[]) ;
}
}
public function getObject():T
{
if(counter > 0)
return pool[--counter];
else
throw new Error("You exhausted the pool!");
}
public function disposeObject(s:T):Void
{
pool[counter++] = s;
}
}
Written by kamal
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Haxe
Authors
designerkamal
1.394K
ooflorent
1.376K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#