On 12/19/2011 05:23 AM, a wrote:
In case of passing GC memory to C functions, I would prefer to just
disallow the C code to capture the reference, and to disable GC while
the C function runs.
Wouldn't this be a problem with non concurrent GC? If you have multiple threads
that spend most of the time in C function calls (for example performing IO),
garbage collection would be impossible most of the time. In the extreme case
garbage would never be collected.
Garbage collection is triggered by allocations. The C function does not
perform GC allocations. While the memory is allocated, the GC is
enabled. With non-concurrent GC there is certainly no issue, but the GC
would have to be disabled and re-enabled on by thread basis.
Couldn't we just require that the programmer keeps a reference to the memory
passed to C in a D variable? AFAIK python does it that way, but
I don't use python enough to know if it causes serious problems there.
The issue is that a copying GC must be able to move the memory. It
cannot do that if there are references it does not know about, because
it has to update all references to the moved memory. If you just keep
around a reference to the memory, your reference will be updated, but
the reference from the C code will be left dangling.