toStringz lifetime
Ali Çehreli
acehreli at yahoo.com
Sun Oct 25 10:37:53 UTC 2020
On 10/25/20 3:19 AM, rikki cattermole wrote:
> On 25/10/2020 11:03 PM, Ali Çehreli wrote:
>> Does the GC see that local variable 'name' that is on the C side? What
>> I don't know is whether the GC is aware only of the stack frames of D
>> functions or the entire thread, which would include the C caller's
>> 'name'.
>
> The thread stack frame that is registered with the D GC will know about
> the D side and may know about the C side.
>
> It depends on what the C side is doing.
>
> If the C side went ahead and made a new stack frame via a fiber... it
> won't know about it. But even if it did, the D stack frame is still
> alive and pinning that bit of memory.
>
> Ultimately, if the C side puts that pointer some place like a global or
> send it to another thread, there are no guarantees that things will play
> out well.
Thanks. That's reassuring. :) So, as long as the D function documents
that the C side should make a copy if they want to extend the string's
lifetime it's their responsibility. And from your description I
understand that they have time to make that copy.
Ali
More information about the Digitalmars-d-learn
mailing list