Allocator-aware @safe reference counting is still not possible
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Mon Jan 30 12:30:01 UTC 2023
On 31/01/2023 1:17 AM, Dukc wrote:
> On Monday, 30 January 2023 at 01:07:32 UTC, Timon Gehr wrote:
>>> Working code:
>>> https://github.com/ntrel/stuff/blob/master/typecons/isolated.d
>>>
>>> Isolated could go in std.typecons.
>>
>> Isolated is not sufficient, you also have to guarantee the pointer was
>> allocated with `malloc`.
>
> This could be accomplished with building a wrapper type over `malloc`ed
> pointers. `@safe` `free` would accept only them, not any isolated pointer.
This is just horrible. You might as well call it DynamicArray which is
exactly what I recommend you do, use data structures and not call
allocators directly!
Of course we could add ``@require(AllocatorAware)`` and call it a day.
That would at least force people to audit their code and realize hey...
this isn't something I should be using directly but still allow passing
allocators around.
More information about the Digitalmars-d
mailing list