假设 我调用的 某个函数 int fn(char **data, int len); fn函数内部malloc data数据出来
用go来调用的话 要释放吗?怎么释放?
用go来调用的话 要释放吗?怎么释放?
2
gihnius Dec 2, 2013 我只是新手.
data := C.malloc(...) defer C.free(data) 如果 data 在fn 里面 malloc 就不知道了.... 为什么不在里面 free 呢? |
3
guotie Dec 2, 2013 要释放
C.free(data) |
5
wwwjfy Dec 4, 2013 不是高手,用过两天..
http://golang.org/cmd/cgo/ // Go string to C string // The C string is allocated in the C heap using malloc. // It is the caller's responsibility to arrange for it to be // freed, such as by calling C.free (be sure to include stdlib.h // if C.free is needed). |