The main language I'm interested in doing object pooling in is AS3, which is known to need it in many cases. In the past I've always made a brand new factory class for every type I was going to try to pool, the parameters of its "object-producing" function being the same as those of that type's constructor. Essentially:
static public function produce(<list of paramaters>):<type>
var obj:<type> = m_arryPool.pop();
// do something with the arguments passed to produce()
return new obj(<arguments passed to produce()>);
But recently I've been trying to think of a way to avoid re-writing this sort of boiler-plate code for every single type I want to pool, but probably without forfeiting the idea of passing arguments around to the returned objects as in the above example, and definitely without putting so much dynamic functionality and stuff in there that it just winds up slowing stuff down too much.
I'm still a little green at object-pooling. I know a one-size-fits-all pooling factory will probably not work out in all cases (AS3's
Function.apply(), for instance, doesn't support constructors), but when does it get to the point that you're just passing in so many arguments to the
produce() function, using so many untyped variables, going through so many dictionaries and lists, etc., that it just isn't hardly worth it anymore?
I know this question may be slightly subjective, but I do believe there are largely objective answers to it. I'm mainly interested in how this would apply to AS3, but I'm also interested in (and asking for) a general answer. Is the best way to handle it generally just to go ahead and write boilerplate code for every type you plan to pool or something like that? Thanks!