Best data structure for a particle system?

Ivan Kazmenko gassa at mail.ru
Fri Nov 15 07:30:52 PST 2013


On Friday, 15 November 2013 at 14:01:36 UTC, Chris Cain wrote:
> 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.

Not exactly so.  If you decrease the length, the capacity is set 
to 0.  If you then try to increase it, you must use 
assumeSafeAppend on the array, or it will be reallocated.  
Alternatively, you may choose to allocate a large enough array 
once and then create a wrapper struct to store the currently used 
length.

See the explanation of how array slices work in D:
http://dlang.org/d-array-article.html

Or a thread I started when learning to use D arrays as stacks and 
queues without wrappers:
http://forum.dlang.org/thread/yrxspdrpusrrijmfyldc@forum.dlang.org?page=1

Ivan Kazmenko.


More information about the Digitalmars-d-learn mailing list