Short article on std.parallism

Jonathan M Davis jmdavisProg at gmx.com
Mon May 30 23:35:05 PDT 2011


On 2011-05-30 23:21, Andrej Mitrovic wrote:
> Why doesn't Appender overload opCatAssign? It would be almost trivial
> to replace usage of existing arrays with Appender, instead of having
> to replace all calls with var.put().
> 
> And why doesn't it overload toString? You can't print its contents to
> stdout like you can with slices.
> 
> And why can't you slice an Appender?
> 
> I see a lot of drawbacks with the only benefit being performance. Now,
> if Appender had some syntax sugar to make it appear as if it were a
> simple dynamic array (well, slice..), that would be sweet and would
> encourage its use, at least with me. Otherwise it just looks ugly
> compared to the sexy D arrays. It looks like everything is becoming a
> template in a library these days..

If you could slice an Appender, it would lose all of its guarantees. It can do 
what it does in part because it knows that it hasn't been sliced. If you were 
slicing it, then you'd have to worry about possible reallocations which loses 
all of the benefit of Appender in the first place. Appender only works because 
it's creating an array. If you tried to use it as a dynamic array in general, 
it wouldn't work. It's purely an optimization for creating arrays. ~= can't be 
made to do what Appender does, and if you tried to make Appender do what ~= 
does, then Appender couldn't do what it currently does. Appender has a very 
specific purpose and no one should be trying to replace dynamic arrays with 
it. It's just that if you want to get your code to be as fast as possible, 
there are cases where using Appender is a good idea. Beyond that, you 
shouldn't be using Appender.

- Jonathan M Davis


More information about the Digitalmars-d-announce mailing list