Allocating delegate on heap?
Bill Baxter
dnewsgroup at billbaxter.com
Mon Feb 19 13:22:32 PST 2007
Rick Mann wrote:
> Kirk McDonald Wrote:
>
>> However, there's a very important detail which you should not overlook:
>> You are passing a pointer to GC-controlled data to a C library. The D
>> garbage collector doesn't scan the C library for references, so you will
>> need to keep a reference to any structs you pass to Carbon in your D
>> code. Otherwise, the GC will feel free to collect them when you least
>> expect it. This can be done with an AA:
>
> Yes, thank you, I was aware of that. As it turns out, there's other stuff I need to do with my delegate that I can't do (namely, treat the .ptr portion of it as a pointer to a class derived from some interface Foo), so I ended up having to create a little class wrapper.
>
> I add the class to the GC's root with std.gc.addRoot(). This should work, right (rather than storing it in an AA)?
That's going to tie you to a particular gc implementation, though. So I
think the practice should be avoided unless you have a compelling reason
to do it that way.
--bb
More information about the Digitalmars-d-learn
mailing list