V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
xdeng
V2EX  ›  Go 编程语言

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

  •  
  •   xdeng · 2013-12-02 18:26:08 +08:00 · 1734 次点击
    这是一个创建于 3790 天前的主题,其中的信息可能已经有所发展或是发生改变。
    假设 我调用的 某个函数 int fn(char **data, int len); fn函数内部malloc data数据出来

    用go来调用的话 要释放吗?怎么释放?
    6 条回复    1970-01-01 08:00:00 +08:00
    xdeng
        1
    xdeng  
    OP
       2013-12-02 18:27:59 +08:00
    @gihnius
    @wwwjfy 求教两位高手
    gihnius
        2
    gihnius  
       2013-12-02 21:51:10 +08:00   ❤️ 1
    我只是新手.

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

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

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

    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
        6
    xdeng  
    OP
       2013-12-04 22:17:05 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5719 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 02:29 · PVG 10:29 · LAX 19:29 · JFK 22:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.