On Sunday, 8 December 2013 at 19:00:29 UTC, Namespace wrote:
> Just using new and GC.free would be fine, but there is really no > need to burden the GC with this at all; it's a textbook case for
 > C's malloc/free.
The GC relies also on malloc / free.

Yes, it does. However, obviously it does a lot more than just call malloc/free.

If you statically know the lifetime of a chunk of memory, then there really is no point invoking all that extra heavyweight code* when you can just DIY at no extra cost.**


*and adding to the collection burden (if triggered while the memory is in scope)

**However, take care with unique pointers from inside the allocated block to resources outside the block, as the GC might not be able to find them later (see P.S.).


P.S. does anyone know how the GC interacts with core.stdc.free? I.e. if you free a pointer, but don't null the pointer, presumably the GC will still scan the memory despite it being freed. Isn't this undefined behaviour?

Reply via email to