The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
46fo

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

  •  
  •   46fo · Dec 2, 2013 · 2426 views
    This topic created in 4633 days ago, the information mentioned may be changed or developed.
    假设 我调用的 某个函数 int fn(char **data, int len); fn函数内部malloc data数据出来

    用go来调用的话 要释放吗?怎么释放?
    6 replies    1970-01-01 08:00:00 +08:00
    46fo
        1
    46fo  
    OP
       Dec 2, 2013
    @gihnius
    @wwwjfy 求教两位高手
    gihnius
        2
    gihnius  
       Dec 2, 2013   ❤️ 1
    我只是新手.

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

    如果 data 在fn 里面 malloc 就不知道了.... 为什么不在里面 free 呢?
    guotie
        3
    guotie  
       Dec 2, 2013   ❤️ 1
    要释放

    C.free(data)
    46fo
        4
    46fo  
    OP
       Dec 2, 2013 via iPhone
    @gihnius 都说调用的是dll的函数来的 要调用者释放
    wwwjfy
        5
    wwwjfy  
       Dec 4, 2013   ❤️ 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).
    46fo
        6
    46fo  
    OP
       Dec 4, 2013
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   947 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:32 · PVG 02:32 · LAX 11:32 · JFK 14:32
    ♥ Do have faith in what you're doing.