Interesting Memory Optimization
Xinok
xinok at live.com
Fri Mar 16 11:44:52 PDT 2012
On Friday, 16 March 2012 at 15:41:32 UTC, Timon Gehr wrote:
> On 03/16/2012 03:28 PM, H. S. Teoh wrote:
>> More to the point, does dmd perform this optimization
>> currently?
>>
>>
>> T
>>
>
> No.
>
> immutable string a = "123";
> immutable string b = a;
>
> void main(){writeln(a.ptr is b.ptr);} // "false"
It actually does, but only identical strings. It doesn't seem to
do strings within strings.
void foo(string a){
string b = "123";
writeln(a is b);
}
void main(){
string a = "123";
string b = "456";
string c = "123456";
foo(a);
foo(b);
foo(c);
}
Prints:
true
false
false
More information about the Digitalmars-d
mailing list