4 ms·
Wouldn't it be safe to use in C-land as long as you kept a reference to it in Go-land? Something like: Create memory in Go-land Use memory in C-land Dis
by AnimalMuppet 12y ago
Wouldn't it be safe to use in C-land as long as you kept a reference to it in Go-land? Something like:
Create memory in Go-land
Use memory in C-land
Dispose of reference to memory in Go-land
That becomes a bit problematic if the C-land use is for a long-running process - you need a go object that owns the memory that has a lifetime that (at least) matches the lifetime of the C code execution.
- danieldk 12y agoCurrently, yes. Once Go has a moving garbage collector (soon-ish), no. A moving garbage collector can move objects around. This would invalidate pointers in C, since the GC can run concurrently with C code (even if it didn't, it would invalidate pointers to object allocated in Go in C structs). To make things work, you have to allocate date used in C in C and pass Go variables only by value.