Post about comparing C, C++ and D performance with a real world project
Ali Çehreli
acehreli at yahoo.com
Fri Dec 8 01:44:02 UTC 2017
On 12/07/2017 03:07 PM, Iain Buclaw wrote:
> On 7 December 2017 at 23:39, Daniel Kozak <kozzi11 at gmail.com> wrote:
>> The other slowdown is caused by concatenation. Because std::string += is
>> more simillar to std.array.(Ref)Appender
>>
>
> Correct. The semantics of ~= mean that the memory is copied around to
> a new allocation every time (unless the array is marked
> assumeSafeAppend).
>
You must have meant ~, not ~= because luckily, it is assumeSafeAppend
when there is just one slice. ~= is not that bad in that case:
import std.stdio;
void main() {
int[] a;
foreach (i; 0 .. 10) {
a ~= i;
writeln(a.ptr);
}
}
7F621818D020
7F621818D020
7F621818D020
7F621818C100
7F621818C100
7F621818C100
7F621818C100
7F621818B040
7F621818B040
7F621818B040
Ali
More information about the Digitalmars-d
mailing list