Sean Kelly wrote:
Walter Bright Wrote:
Mixing D's gc world with manually managed memory isn't hard, as
long as the following rules are followed:

1. don't allocate in one language and expect to free in another 2.
keep a 'root' to all gc allocated data in the D side of the fence (otherwise it may get collected)

This may actually work in D 2.0.  core.thread has thread_attachThis()
to make the D GC aware of an external thread, and gc_malloc() is an
extern (C) function.  I haven't tested this extensively however, so
if you're keen to try it, please let me know if there are any
problems.

There's a more fundamental problem. There is simply no reliable way to find all the static data segments in a program. I talked with Hans Boehm about this, he uses some horrific kludges to try and do it in the Boehm gc. This problem is on every OS I've checked.

Windows has the bizarrely useless ability to find the beginning of your TLS data segments, but not the end! Useless.

The D runtime knows about D's allocated segments because I fixed the object file generation to provide that information. But if it's some other compiler, it's hosed.

Therefore, one has to keep on the D side of the fence roots to all data structures passed to foreign languages. It's pretty easy to do, just don't forget it!

Reply via email to