Why are commands executing out of order?

Era Scarecrow rtcvb32 at yahoo.com
Sat Feb 2 04:50:58 PST 2013


On Saturday, 2 February 2013 at 11:33:07 UTC, Namespace wrote:
> I'm was quite surprised as I had heard the first time of these 
> 'appender'.
> Therefore I'm asking me:
> Why is the 'appender' method so much more efficient?

  Because concatenation likely will end up relocating the memory 
over and over again (possibly lots of abandoned slices too) 
whereas the appender will allocated & reuse the same buffer. On 
the other hand you might be better off (depending on the need) 
with just reserving a lot more memory (close to what you need or 
slightly larger) and then concatenation will perform much better. 
But if it need to reallocate then you've still got the same 
problem with slices where with the appender you probably won't.

  I tend to reserve string concatenation for assert messages, and 
quicker & dirty text manipulation/building like during ctfe. 
Outside of those I use alternatives first.


More information about the Digitalmars-d-learn mailing list