Memory safety depends entirely on GC ?

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 21 14:57:11 PST 2015


On 2/21/15 2:13 PM, Peter Alexander wrote:
> On Saturday, 21 February 2015 at 20:13:26 UTC, deadalnix wrote:
>> On Saturday, 21 February 2015 at 19:38:02 UTC, Peter Alexander wrote:
>>> @safe @nogc
>>>
>>> :-)
>>>
>>> (I rewrote the post a few times. Originally I just wrote "mark main
>>> @safe @nogc and you're fine", but I think it's a bit misleading since
>>> @nogc is still difficult to use, so I wrote about that instead and
>>> forgot to mention @safe at all. Thanks for pointing out.)
>>
>> free is an unsafe operation. Unless you don't allocate at all or
>> choose to leak everything, you won't be able to be safe and nogc.
>>
>> The only way out that I know of is an ownership system.
>
> malloc+free can be trusted if wrapped in something like a ref counted
> pointer, no?

There's more to it, e.g. access to the underlying raw pointer must be 
carefully restricted. -- Andrei



More information about the Digitalmars-d mailing list