I am working on a project where i have a C application that needs to call an sdk that is written in Go. We have created a wrapper DLL that we can invoke from our C application. However, the marshaling of non-primitives has me a bit stumped.
Right now, we are able to return a C.String() this works but there are two problems.
1.) This is not safe since it requires null term.
2.) We cant call C.free so it’s a leak.
I haven’t been able to find any clear answer on this. Is your standard “free” and “malloc” the same as c.free and c.malloc. Is it safe to alloc in go and free in C and vice versa? I haven’t seen any language docs supporting either way. Since this production, I am hoping to find clear documentation in the language.
The other option is to purely alloc in C and then fill the buffer in go, but as I am unsure of the memory management, I wanted to be certain this won’t have any unintended side effects (alignment issues/etc).
Thank’s in advanced.