[Article] D's Garbage Collector Problem

via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 14 06:30:33 PDT 2014


On Saturday, 13 September 2014 at 19:20:51 UTC, Timon Gehr wrote:
> On 09/13/2014 09:07 PM, "Marc =?UTF-8?B?U2Now7x0eiI=?= 
> <schuetzm at gmx.net>" wrote:
>> Wouldn't `const` be enough? AFAICS, `immutable` is mostly 
>> useful for
>> shared data.
>
> const prevents modification, but does not guarantee that no 
> modification takes place elsewhere. I.e. it enables fewer 
> program transformations.

But as it is thread-local, is it really relevant (for 
optimization)? I can see two situations where it can potentially 
matter: pointer parameter aliasing, and calls to 
function/delegate calls that might modify a value referenced by a 
pointer.

In practice the latter is probably not so important for 
optimizations, because the compiler would most likely have a hard 
time caching a value across a function call because of register 
pressure, so a reload would be necessary anyway. I don't know 
about parameter aliasing, but I guess it only makes a difference 
in corner cases. In these cases, it's easy to forbid it by 
contract (as slice copying does).


More information about the Digitalmars-d mailing list