Best data structure for a particle system?

bearophile bearophileHUGS at lycos.com
Fri Nov 15 06:08:19 PST 2013


Chris Cain:

> Instead of having a "dead flag", you could swap ( 
> http://dlang.org/phobos/std_algorithm.html#swap ) the dying 
> particle with the last particle in the list and then decrement 
> the list's length.

If the array is long you are accessing a cold part of it to swap 
with the end.


> By default (using the default GC and everything), D does not 
> reallocate a dynamic array every time you change the length 
> (even increasing it), so this will still be okay with 
> allocations.

The situation is a little more complex, there is a capacity field 
that I think is kept in a cold place of the array, it's also 
cached, but only if you append to just one array, etc.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list