Want reasonable reference counting? Disable automatic sharing of immutable

rikki cattermole rikki at cattermole.co.nz
Mon Nov 15 21:30:29 UTC 2021


On 16/11/2021 4:23 AM, Timon Gehr wrote:
> On 15.11.21 15:27, deadalnix wrote:
>> On Monday, 15 November 2021 at 12:24:33 UTC, Timon Gehr wrote:
>>> On 15.11.21 11:36, rikki cattermole wrote:
>>>>
>>>> On 15/11/2021 10:28 PM, Danni Coy wrote:
>>>>> that feels like a single object from a user perspective?
>>>>
>>>> The most important thing about this is: it'll all be in continuous 
>>>> memory.
>>>>
>>>> Perfect for all of your crashing needs due to read only memory!
>>>
>>> Whoever allocates the object knows the memory layout and can put it 
>>> in writable memory.
>>
>> If the object is allocated, it HAS TO BE in mutable memory.
> 
> No, you can allocate it on the GC heap in CTFE and then store it in the 
> immutable data segment at runtime by assigning to a static immutable 
> variable.
> 
> In general, you can allocate first and then change the protection 
> attributes on the page later.

Exactly.

There is nothing stopping the compiler putting immutable values in ROM, 
nor the user who didn't know that something like __mutable is in use 
from making memory they allocated read only.

const and immutables are compiler guarantees, and we shouldn't be 
wanting the compiler to lie to us in our misunderstandings.


More information about the Digitalmars-d mailing list