Sunday, November 7, 2010

ntParticleSystem - memory handling (cont'd)

It's probably faster and easier to maintain the code if there's a fixed size particle array allocated in memory and forces will only applied to living particles. I will discontinue following the approach with having a linked list to living particles, since this requires a lot of management whenever a new particle is born or dies.

ntParticleSystem - memory handling

The particle cloud must be able to hold an amount of probably up to 1,000,000 particles. In addition to that, it's not necessarily the case that all of the space will be used. So there are only three ways coming to my mind to deal with this. If we want an extensible memory that allocates only - or a bit more than - the required space, we can use linked lists or dynamic memory. Advantage is that the user don't need to bother with how much particles he needs. Disadvantage with the linked lists is that for each generated particle new memory will be allocated which will cause performance to suffer. Same applies to dynamic memory, in which we'd keep on doubling the available memory in case more than required memory is requested or halve it if less than half of it is requested. Since it is not intended to create huge complex particle dynamics simulations, we don't necessarily need this amount of flexibility at the cost of performance. So I rather prefer the static memory size, but still there's something interesting about the linked lists. Considering that the particle engine will run through the list of allocated particles, it can make a big difference if it runs through a list of particles in which most of the particles are inactive (=dead). So a linked list would provide a guide through only the living particles. This way the particle engine will only process the active (=living) particles. But allocating memory each time a particle is spawned come at a high cost, especially when thousands of particles are spawned for each simulation step. So it's probably the best way to have a linked list, which points to the living particles in the fixed size particle array. I have to check this out.

ntParticleSystem

A general purpose particle system is requested to be developed. General purpose in this case means, that it provides an easily accessible interface to process geometric data and simulation settings and return a particle cloud with processed and instantiated input geometry. The particle system follows simple concepts. Simulation globals which contain emission details, force and particle settings are provided to the system. The system is capable of generating emitters, particle clouds, force fields, handling of dependencies to each other. The system class takes care of controlling the simulation procedures, provides the interface for returning the processed particle cloud in the form the overlying application requires it and triggers particle system-wide memory cleaning routines when deleted. It should also provide an API to allow custom forces and eventually custom particle and emitter classes to be developed. Concerning memory handling, I rather go for stability and speed than for dynamic extendability. This concern needs further research.