Go: A new system programing language
Walter Bright
newshound1 at digitalmars.com
Wed Nov 18 09:56:29 PST 2009
Mike Hearn 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)
>
> Yes it's the second that's the tough part. For instance consider the
> case of passing a callback (delegate) to the RPC system written in
> c++. How do you keep the associated data rooted without causing
> leaks? You'd need to remember to manually add it to the gc roots when
> the callback object is created and then unroot them when it's
> invoked. So this needs some kind of glue/binding system.
>
> I'm not saying it's impossible or even hard. Just that I've seen such
> things done before and they were non-trivial.
Most of the time, nothing needs to be done because the reference is on
the parameter stack that calls the C function.
For the callback object, manually adding/removing the root (there are
calls to the gc to do this) shouldn't be any more onerous than manually
managing memory for it, which is done in C/C++ anyway.
More information about the Digitalmars-d
mailing list