4 ms·
Correct me if I'm wrong, but I think Go lets you share pointers with other languages/runtimes. I think Go doesn't allow you to pass ownership of the pointer to
by weberc2 9y ago
Correct me if I'm wrong, but I think Go lets you share pointers with other languages/runtimes. I think Go doesn't allow you to pass ownership of the pointer to another language, and you need to make sure the pointer is no longer used by the other language by the time Go cleans it up, but I think you can (for example) pass a Go pointer into C. And assuming I'm right about that point, I think this approach is also roughly what was outlined in the Oxidation Plan (Python won't own resources allocated from Rust and vice versa).
- danieldk 9y agoI think Go doesn't allow you to pass ownership of the pointer to another language, and you need to make sure the pointer is no longer used by the other language by the time Go cleans it up, but I think you can (for example) pass a Go pointer into C. Yes, you can, but there are more constraints. E.g. you are also not permitted to pass a pointer to Go memory that contains Go pointers. There is a detailed description here: https://golang.org/cmd/cgo/#hdr-Passing_pointers https://golang.org/cmd/cgo/#hdr-Passing_pointers Also, it used to be the case that cgo calls were relatively expensive (definitely not something you want to do in a hot loop). I am not sure if this is still true, but it was when I was using Go daily for projects.