`clear`ing a dynamic array
Shriramana Sharma via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Oct 25 04:45:50 PDT 2015
Jonathan M Davis via Digitalmars-d-learn wrote:
> 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
I get the part about Appender helping to make an output range of a regular
array, but I'm not sure how it is supposed to make appending "more
efficient". I just had a look at the std.array code for appender and
couldn't figure what was so special – obviously it's my limited knowledge.
http://dlang.org/arrays.html#resize says: """Also, you may wish to utilize
the phobos reserve function to pre-allocate array data to use with the
append operator."""
I presume this means
http://dlang.org/phobos/std_array.html#.Appender.reserve but how `append` is
considered an operator is beyond me.
Anyhow, is `reserve` the only thing that makes this more efficient? How is
this more efficient than setting the .length of the dynamic array directly?
I see there's a lot of logic going into ensureAddable() but doesn't this
logic happen within druntime for the regular dynamic arrays itself?
--
Shriramana Sharma, Penguin #395953
More information about the Digitalmars-d-learn
mailing list