I know this similar question has been asked before, and it received various suggestions, but I felt I needed to ask it again in a specific way for my problem, along with getting input on the better way to really solve it.
My goal is to move looping code from the Go side into the C side to avoid (and at least test) the overhead of multiple cgo calls per loop. I had a few different ideas of the way to communicate between the two functions.
The data is the float pixels values for an image, packed into an array like R,G,B,R,G,B,...
func GetImageFloatRGB() float32
1. malloc, populate, and return a float* from C to Go. Then either copy it into a float32 and free, or set it on a slice header
2. malloc on the Go side and pass in the float*, then do either of the previously mentioned steps
3. make() a float32 on the Go side, and pass the backing array pointer into the C call to let it populate
I haven't really had much luck with any of them yet, as no matter what I try I end up with an all zero array as the result. Although #3, if possible, seems really cool since theoretically I wouldn't have to do anything after the cgo call, as the slice would already be populated.
Both sides of the call have full knowledge of the length of the slice/array.
Most likely I am just getting the casting wrong somewhere, but I would love to first focus on the best suggested approach for passing the data, and then actually figure out the correct way to *do* it. I could show some of my attempts after someone offers the advice on which one would be best.