On 6/27/17 11:24 AM, Steven Schveighoffer wrote:
On 6/27/17 9:25 AM, Guillaume Piolat wrote:
That's how the GC-proof resource class came to existence, after many
destruction bugs, and it let's you use the GC as a detector for
non-deterministic destruction. I miss it in @nogc :)
https://p0nce.github.io/d-idioms/#GC-proof-resource-class
There are definitely better ways to do this than trying to allocate and
catching an error. The GC knows the GC is running, use that mechanism
instead :)
https://github.com/dlang/druntime/blob/master/src/gc/gcinterface.d#L189
https://github.com/dlang/druntime/blob/master/src/core/memory.d#L150
Apparently that info is limited to the core.memory package. But it's
extern(C), so declaring the prototype should work. Should be much more
efficient than allocating a byte (which I see you don't delete if it
works), and catching an error.
-Steve