Allocator-aware @safe reference counting is still not possible

Timon Gehr timon.gehr at gmx.ch
Mon Jan 30 12:26:09 UTC 2023


On 1/30/23 13:19, jmh530 wrote:
> On Monday, 30 January 2023 at 01:07:32 UTC, Timon Gehr wrote:
>> On 1/28/23 16:56, Nick Treleaven wrote:
>>> [snip]
>>> Isolated could go in std.typecons.
>>
>> Isolated is not sufficient, you also have to guarantee the pointer was 
>> allocated with `malloc`.
> 
> Could you explain in a bit more detail why this is the case? Thanks.

https://en.cppreference.com/w/c/memory/free

"The behavior is undefined if the value of ptr does not equal a value 
returned earlier by malloc(), calloc(), realloc(), or aligned_alloc()."

Undefined behavior is not memory safe.


More information about the Digitalmars-d mailing list