[Issue 22271] New: Appending to an empty array reallocate
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Sep 3 14:20:15 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22271
Issue ID: 22271
Summary: Appending to an empty array reallocate
Product: D
Version: D2
Hardware: x86
OS: Windows
Status: NEW
Severity: enhancement
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: deadalnix at gmail.com
See sample code:
string x = "foobar";
string y;
y ~= x;
import std.stdio;
writefln("%x %x", x.ptr, y.ptr);
We can see here that a new allocation is done and the content of x copied in
it. However, this reallocation is superfluous and a waste of perfectly good CPU
cycles and memory :)
--
More information about the Digitalmars-d-bugs
mailing list