Interesting Memory Optimization
Xinok
xinok at live.com
Fri Mar 16 12:04:34 PDT 2012
On Friday, 16 March 2012 at 18:56:00 UTC, Timon Gehr wrote:
> It can't because there must be a terminating zero byte. It does
> not do it even if it could though.
>
>
> immutable string x = "123";
> immutable string y = "123";
>
> void foo(string a){
> string b = "123";
> writeln(a is b);
> }
>
> void main(){
> string a = "123";
> string b = "456";
> string c = "456123";
> foo(c[3..$]); // false
> writeln(x is y); // false
> writeln(a is x); // false
> writeln(b is x); // false
> writeln(a is y); // false
> writeln(b is y); // false
> foo(a); // true
> foo(b); // false
> }
So while D does pool strings, it doesn't seem to optimize
globals. I couldn't find anything about it on the bug tracker.
More information about the Digitalmars-d
mailing list