3 ms·
> access to C libraries Have you tried the "cgo" facility and found it lacking? If so, how?
by everybodyknows 7y ago
> access to C libraries
Have you tried the "cgo" facility and found it lacking? If so, how?
- masklinn 7y agocgo is easy to use but pretty literally opts you into a different language entirely: https://dave.cheney.net/2016/01/18/cgo-is-not-go https://dave.cheney.net/2016/01/18/cgo-is-not-go
- jpgvm 7y agoYeah pretty much. Using cgo has been the source of near endless pain for me when writing systems software. It criples portability, drastically changes runtime behaviours and generally is best dealt with by CGO_ENABLED=0.
- gwd 7y agoIn addition, cgo calls are often reeely slow. I've been using the sqlite bindings to go for projects recently. sqlite doesn't allow you to write your own in-language functions, but instead allows you to write your own callback. I recently did some benchmarks, and the golang callback for a simple function was 20x slower than implementing it in C (1600us vs 80us), presumably due to all the marshaling and reflection required.
- masklinn 7y agoYes, you really don't want to use cgo to call small functions or helpers, the overhead is enormous.