Array concatenation vs. Appender

Era Scarecrow rtcvb32 at yahoo.com
Sat Feb 2 17:27:16 PST 2013


On Saturday, 2 February 2013 at 15:47:37 UTC, FG wrote:
> Yeah but let us move reallocation out of the equation. 
> Reserving space limits the amount of RAM used and can avoid 
> reallocations all together but in a little test it came out 
> that still appender is 2.5-4 times faster than tab ~= str, 
> where tab is char[] (same when it is ubyte[]). Why is that?

  Reserving doesn't mean it has to allocate any memory at all; 
That's up to the implementation of the runtime and OS, it may 
just say 'any allocations not related to this object start after 
address xxx', then as the reserved space needs more it requests 
the larger space from the OS. The limitations of how much you can 
use memory-wise doesn't change as that's determined by the 
infrastructure. (VM and harddrive space doesn't count).

> Why cannot tab ~= fill achieve similar performance as this code?
> Am I missing something important?

  As for how many checks and overhead the runtime has I'm not 
sure. Try compiling the code again with full optimizations on and 
see if it makes a difference. Concatenation may perform better 
like that (as long as relocation/copying isn't done) or maybe 
not...


More information about the Digitalmars-d-learn mailing list