pacote;
import nme.errors.Error;
class ObjectPool <T>
{
pool var privado: Array <T>;
contador var privado: 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;
}
}