I'm trying to create an object pooling framework. Every time a client requests an objects of some type, I return an object from a cache (a queue) or create a new object if there isn't any in the cache.
Now when the client code is done with the object, passes it to the framework to be cached again. But for this pattern to work, the object needs to be reset to initial state. every field has to be set to its default(T)
. Doing this manually for every class would be error prone and tedious work.
public void Reset(){
x=0;
y=0;
...
}
And of course performance is a primary concern. I'm looking for the most efficient solution.
EDIT:
As for motivation, this is a unity3d game project and garbage collection is a huge issue in unity. Every byte you save from garbage collection matters. So it is desirable to cache objects in contrast to the fastest, easiest, more reasonable way of just creating new objects.