Best data structure for a particle system?

Chris Cain clcain at uncg.edu
Fri Nov 15 07:23:08 PST 2013


On Friday, 15 November 2013 at 14:08:20 UTC, bearophile wrote:
> 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.

An alternative might be hold an array and manage a slice to that 
array. "Appending" would just be reslicing the array.

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

Sure. But on a long array, the time taken to iterate over the 
entire array looking for a dead particle to recycle would take 
time as well. Not to mention that removing the dead particle by 
swapping it with the end would likely keep the overall array 
smaller and, thus, more likely to fit completely in the cache. 
There's a lot to be said about keeping memory usage as compact as 
possible.

Is there any empirical data to suggest either approach is better? 
There's factors that could suggest either one might be faster 
depending on the situation.


More information about the Digitalmars-d-learn mailing list