| |
| Posted by Steven Schveighoffer in reply to Mike Parker | PermalinkReply |
|
Steven Schveighoffer
Posted in reply to Mike Parker
| On 5/24/21 8:38 PM, Mike Parker wrote:
> On Monday, 24 May 2021 at 16:16:53 UTC, Steven Schveighoffer wrote:
>> This leaves a GC-collectible allocation in C land. For `puts`, it's fine, as the data is not used past the call, but in something else that might keep it somewhere not accessible to the GC, you'll want to assign that to a variable that lasts as long as the resource is used.
>>
>
> That's what I'm referring to in the conclusion where I say this about what's going to be in Part Two:
>
>> how to avoid a potential problem spot that can arise when passing GC-allocated D strings to C
>
> I'll cover approaches to maintaining a reference, like `GC.addRoot`, and emphasize that it applies to any GC-allocated memory, not just strings.
OK, I'm just concerned people will see the pattern:
```d
somecfunc(str.toStringz);
```
and think that's the end of it.
-Steve
|