Either I'm confused or the gc is

Ali Çehreli acehreli at yahoo.com
Mon Nov 16 21:36:01 UTC 2020

On 11/16/20 1:25 PM, Steven Schveighoffer wrote:

 > I can imagine a situation where it removes the item from the stack to
 > put it somewhere else (e.g. global memory or on the C heap)
 > *temporarily*

Good point. For example, they can provide the address of the member of a 
heap-allocated object:

   Obj * obj = malloc(/* ... */);
                                // <-- Another thread triggers a
                                //     GC collection at this point.

   printf("%d", obj.member);    // <-- Potentially too late.

This is hard to communicate to the callers. I said "safe to use for 
immediate consumption" but still not safe. Documenting like "pointer to 
stack allocated data only please" may be too confusing for casual users. 
So, the safest thing would be to make a copy with toStringz.

Of course, strings are just one type. I pass GC allocated large buffers 
to the C side without copying. Luckily, I am the only consumer so far 
and things seem to work. :)


More information about the Digitalmars-d mailing list