谁用过 go语言 调用win 的 dll 的?

2013-12-02 18:26:08 +08:00
 xdeng
假设 我调用的 某个函数 int fn(char **data, int len); fn函数内部malloc data数据出来

用go来调用的话 要释放吗?怎么释放?
1741 次点击
所在节点    Go 编程语言
6 条回复
xdeng
2013-12-02 18:27:59 +08:00
@gihnius
@wwwjfy 求教两位高手
gihnius
2013-12-02 21:51:10 +08:00
我只是新手.

data := C.malloc(...)
defer C.free(data)

如果 data 在fn 里面 malloc 就不知道了.... 为什么不在里面 free 呢?
guotie
2013-12-02 21:56:07 +08:00
要释放

C.free(data)
xdeng
2013-12-02 22:17:10 +08:00
@gihnius 都说调用的是dll的函数来的 要调用者释放
wwwjfy
2013-12-04 21:37:17 +08:00
不是高手,用过两天..

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).
xdeng
2013-12-04 22:17:05 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/91514

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX