On Sunday, 21 August 2016 at 16:38:09 UTC, Cauterite wrote:
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote:
5) Is there a way to do simple heap allocation with 'new' while ensuring the GC doesn't deallocate until I want it to?

I can answer this at least,
If you don't want the GC to ever collect the object itself, here's the best way: Allocate the object with a non-GC allocator (such as std.c.malloc ), then use `emplace` to construct the object in that memory ( http://dlang.org/phobos/std_conv.html#.emplace ).

I see - That makes sense, but is there no way to "pause/stop" the GC, but still be able to use the 'new' syntax? I like how clear the syntax is, I just don't _always_ want the GC. I'm thinking of something like:

core.memory.GC.disable();
Obj o = new Obj();
/* ...use o... */
core.memory.GC.free(o); // or whatever

if possible, is there a drawback to this (other than no automatic GC) compared to say, malloc?

Regarding the marking, I guess my question is: what must be done to ensure something allocated with 'new' will be a candidate for auto-collection later (when GC is enabled)?

Reply via email to