I'm trying to make a go string from C. I have the pointer and the length, so if I was doing it from go, I could call the C.GoStringN
function.
cgo
generates the GoString
struct, so I was wondering if I could use it directly:
// struct generated by cgo
typedef struct { const char *p; GoInt n; } GoString;
// I have s and n from somewhere else, can I do this ?
const char* s = ... ; // I own this and dont want go to free it
int n = ... ;
GoString st = {s, n } ;
I'm using this in here to make a go string out of a char*
whose lifetime I control. The GoString
is then used as an argument to a go function:
//export Nbytes
func Nbytes(s string) int {
...
}
Will go's garbage collector attempt to reclaim the memory ?