Passing Appender by value

monarch_dodra monarchdodra at gmail.com
Sat Jun 22 08:03:01 PDT 2013


On Saturday, 22 June 2013 at 14:19:45 UTC, Diggory wrote:
> The problem occurs whenever the internal array is resized 
> because what actually happens is that a new array is allocated 
> and the contents copied over - the original Appender still 
> references the original array (or in this case null). The last 
> example only works because when you call "put(2)" it actually 
> allocates an array large enough to hold at least another item 
> as well.
>
> As usual it can be solved by introducing an extra layer of 
> indirection, either by passing by ref or by making Appender 
> store a pointer to a range.

No, it's not that bad, because the "extra layer of indirection" 
is already there. The problem is that said layer isn't actually 
initialized yet...


More information about the Digitalmars-d-learn mailing list