Fast temporary dynamic arrays? (And slicing of them)

Steven Schveighoffer schveiguy at yahoo.com
Tue Sep 7 11:30:38 PDT 2010


On Tue, 07 Sep 2010 12:54:52 -0400, bearophile <bearophileHUGS at lycos.com>  
wrote:

> Steven Schveighoffer:
>> Note that the new appender uses heap data to store its implementation,  
>> so
>> it's not as quick as it could be.  This is per Andrei's requirement that
>> it be a reference type.
>
> Thank you for your answers. But I don't fully understand your answer. Do  
> you mean it uses the Pimpl idiom, and allocates the struct on the heap?

Yes.

> I use appender only when performance is important. The appender is a  
> hack useful because array appending in D is very slow (and even appender  
> is quite slow), so it must be first of all fast, otherwise it's not  
> useful.

Appending is as fast as possible, at the cost of an initial allocation.   
Without this, the capacity would have to be stored inside the array, or be  
aliased, which wouldn't work all that well.

> I generally use appender inside the scope of a single function.
>
> So unless I am missing something I think Andrei requirement is/was wrong.

An appender is an ouput range, so passing it into a function so the  
function can output to it is a requirement.

-Steve


More information about the Digitalmars-d-learn mailing list