Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have no idea as to the particulars here. I'm involved with a project that is working with Go code from another language.

Go doesn't allow you to share pointers to Go objects with other languages/runtimes. So whatever else the pros and cons of each, working with Go from another language can be painful.



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).


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.

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

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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: