`clear`ing a dynamic array

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Oct 25 01:50:21 PDT 2015


On Sunday, October 25, 2015 09:34:25 Shriramana Sharma via Digitalmars-d-learn wrote:
> rsw0x wrote:
>
> > use std.container.array
>
> Thanks all for all the recommendations. When would one use
> std.array.appender with a built-in array vs std.container.array.Array? What
> are the pros and cons on either side?

Appender is for when you you know that you're going to be doing a whole
bunch of appending to an array, and you'd normally only use it when
initially filling in the array, after which you'd just get the array out of
it and use the array. Appender really isn't intended to be used as a
container - just as a way to make appending more efficient or to have an
output range which is an array but which is appended to by put rather than
just assigning to its existing elements. You don't use Appender to not use
arrays or to get full reference semantics from an array.

If you want a container rather than a dynamic array - especially if you're
looking for full reference semantics - then use std.container.array.Array.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list