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/yrxspdrpusrrijmfy...@forum.dlang.org?page=1

Ivan Kazmenko.

Reply via email to