From the D Blog -- Interfacing D with C: Strings Part One
Steven Schveighoffer
schveiguy at gmail.com
Tue May 25 00:58:31 UTC 2021
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
More information about the Digitalmars-d-announce
mailing list