On 4/16/18 4:49 AM, Ali Çehreli wrote:
On 04/15/2018 11:46 PM, WhatMeForget wrote:
>
> I think I got a handle on D's static and dynamic arrays, till I come to
> std.array and see all the shiny new tools. I can understand all the
> replace.. functions, but the appender function gave me pause. The
> documentation says appender "Returns a new Appender or RefAppender
> initialized with a given array."
New Appender allocates new memory. If an array is already available for
an Appender to use, then it's more efficient.
> My first thought that doesn't D's built in arrays already allow
> appending? (at least for dynamic arrays)
Yes but Appender is reported to be faster presumably it uses a different
allocation scheme and may be more free compared to dynamic arrays that
must play well with GC and its pages.
It's because it stores the relevant information in a local type vs.
having to look it up in the GC.
It's also not all opaque calls (they can be inlined).
> Another thing that had me wondering is the use of put()
> down below; doesn't the append syntax (~=) give you the same exact
> functionality; so why bother?
put() is old, ~= is new. Both are supported.
put is required for Appender to be an output range.
-Steve