returning D string from C++?

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 6 09:46:40 PDT 2017


On Sunday, 6 August 2017 at 16:23:01 UTC, bitwise wrote:

> So I guess you're saying I'm covered then? I guess there's no 
> reason I can think of for the GC to stop scanning at the 
> language boundary, let alone any way to actually do that 
> efficiently.

It's not something you can rely on. If the pointer is stored in 
memory allocated from the C heap, then the GC will never see it 
and can pull the rug out from under you. Best to make sure it's 
never collected. If you don't want to keep a reference to it on 
the D side, then call GC.addRoot on the pointer. That way, no 
matter where you hand it off, the GC will consider it as being 
live. When you're done with it, call GC.removeRoot.


More information about the Digitalmars-d-learn mailing list