Inherent code performance advantages of D over C?
Timon Gehr
timon.gehr at gmx.ch
Mon Dec 16 05:06:27 PST 2013
On 12/16/2013 01:53 AM, Walter Bright wrote:
> On 12/15/2013 4:22 PM, jerro wrote:
>>> You, as the guy who wrote the code, will (or should) know that there
>>> are no
>>> other live references, hence you are telling the compiler "trust me,
>>> I know
>>> there aren't any".
>>
>> So, is the intended meaning the following: If there exist any immutable
>> references to the data, mutating it results in undefined behavior? If
>> so, I
>> think the documentation on creating immutable data should explicitly
>> say so.
>
>
> Good idea. I suggest writing a pull request against the documentation
> for this.
We need to be careful to do this right.
Consider what happens when we want to dispose memory using our custom
allocator. The caller clearly needs to own an immutable reference in
order to cast it to mutable and pass it to the storage allocator, where
it will be freed in some way that will sometimes involve updating some
metadata accessible through it. The immutable reference will not be gone
during this process. [1]
Furthermore, existence of references may be indeterministic due to the
garbage collector, and the language does not make any guarantees that
anything is ever collected at all.
Informally speaking, the final specification should probably allow in
some way immutable references to mutated data to _exist_, but not define
_access_ to them.
[1] The language does not allow ownership to be tracked.
More information about the Digitalmars-d
mailing list