Sunday, November 7, 2010

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.

No comments:

Post a Comment