Want reasonable reference counting? Disable automatic sharing of immutable

Walter Bright newshound2 at digitalmars.com
Mon Nov 15 02:04:59 UTC 2021


On 11/14/2021 12:18 PM, Timon Gehr wrote:
> On 14.11.21 20:51, Walter Bright wrote:
>> On 11/14/2021 10:25 AM, Timon Gehr wrote:
>>> How do you manually deallocate an immutable payload?
>>
>> The same way it is done now. Call free().
>>
>> Calling free() on an object ends its lifetime. As I mentioned to Steven, 
>> lifetime and mutability are independent attributes.
>>
> 
> I agree that they are independent attributes, but how does the compiler know 
> that something is an allocation/deallocation function? (My suggestion was to 
> annotate such functions __mutable.)

It's done in @live functions. The functions aren't annotated specially, it's 
just that passing a pointer argument to a non-scope parameter means the pointer 
value is transferred, and is no longer 'live' in the calling function.


More information about the Digitalmars-d mailing list