Should I use particle pools if I have to reinitialize each particle every time I create them

I am creating a particle system in XNA4 and I am facing a problem. My first particle system was a simple list of particles that are instantiated as needed. But then I read about using pools.

My second system consists of a pool full of particles and an emitter / controller. My pool is pretty simple, this is the code:

class Pool<T> where T: new () { public T[] pool; public int nextItem = 0; public Pool(int capacity) { pool = new T[capacity]; for (int i = 0; i < capacity; i++) { pool[i] = new T(); } } public T Create() { return pool[nextItem++]; } public void Destroy(T particle) { pool[--nextItem] = particle; } } 

The problem is that the pool system is much more hungry for the processor. Every time I remove a particle from the pool to my emitter, I have to reinitialize and reset the particles due to the lack of a constructor, and this is a problem.

Does it make sense to use pools if I restart these particles or should I leave pools for arrays of completely identical objects that never change?

+4
source share
1 answer

In an XNA application, object aggregation typically should not speed up initialization. This will speed up garbage collection. GK on consoles is slower, and in a game where your entire update function has 16 milliseconds to run, a collection pause can be noticeably noticeable. This may or may not be a problem for your particular case, especially if it is a PC application, depending on the number and lifetime of the particles that you use.

+5
source

All Articles