On Thursday, 21 January 2016 at 22:20:13 UTC, Dibyendu Majumdar
wrote:
On Thursday, 21 January 2016 at 22:15:13 UTC, Chris Wright
wrote:
Finally, you can use gc_setProxy() with a a GC proxy you
create. Have it throw an exception instead of allocating. That
means you will get crashes instead of memory leaks if
something uses the GC when it shouldn't.
gc_setProxy() and struct Proxy seem not to be part of the
public runtime. You can copy the definitions into your own
project -- they're listed as extern(C) to make that easier.
This may tie you to specific DMD revisions in the case that
the GC interface changes.
Thanks - I am looking for an option where no GC memory
allocation is possible so above looks like the solution.
Regards
Out of curiosity, why would you force not being able to allocate
memory? I understand wanting to disable automatic collection of
memory as it may pause the threads but an allocation through the
GC is just like any other allocation.
Besides you don't need to disable allocations not to use the GC,
you just need not to use the GC. What I mean by that is that if
allocation is disabled and your code needs to allocate through
the GC, your program will crash. So you'll design your code so
that you don't allocate through the GC. But then as your code
doesn't use the GC it doesn't matter wether allocation is
possible or not. If your code doesn't use the GC then the GC
isn't used, no collection, no pause, nothing. So I don't quite
see the point of disabling allocation.
On the other hand disabling collection makes sense, you can still
allocate if you need to (to allocate an exception or an error for
example, in such case it doesn't matter much if memory is
collected as the program terminates).
Sooo.... where's the catch?