@gc attribute for bypassign @nogc
bitwise via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jul 24 17:26:05 PDT 2016
On Monday, 25 July 2016 at 00:05:16 UTC, ketmar wrote:
> On Sunday, 24 July 2016 at 23:30:37 UTC, bitwise wrote:
>> On Sunday, 24 July 2016 at 23:10:18 UTC, Dicebot wrote:
>>> @nogc functions must never ever trigger GC collection cycle,
>>> not under any possible circumstances. Otherwise the attribute
>>> serves no purpose.
>>
>> The fact that you can use malloc() in a @nogc function
>> invalidates this argument.
>
> nope. `malloc()` has nothing to do with garbage collection.
>
> what `@nogc` means is "i won't use built-in allocator with
> garbage collection in this code", not "i won't do any memory
> allocations in this code".
If someone knows all their code is @nogc, they can disable the
GC. If they do that, and then someone GC allocates anyways, it's
a leak. Based on this, an argument could be made that @nogc
should *never* be bypassed. But that argument is made on the
false premise that it's fool-proof in it's current condition.
It's not, because you can already use malloc() in a @nogc
function and leak that memory instead.
Bit
More information about the Digitalmars-d
mailing list