zoukankan      html  css  js  c++  java
  • cgo

    Go references to C
    1、Memory allocations made by C code are not known to Go's memory manager. When you create a C string with C.CString (or any C memory allocation) you must remember to free the memory when you're done with it by calling C.free.

    2 、To access a struct, union, or enum type directly, prefix it with struct_, union_, or enum_, as in C.struct_stat.

    3、The size of any C type T is available as C.sizeof_T, as in C.sizeof_struct_stat.

    4、_, err := C.voidFunc()  C errno variable as an error (use _ to skip the result value if the function returns void).

    C references to Go 
    1、go函数导出,单个返回值与多返回值。found in the _cgo_export.h generated header, after any preambles copied from the cgo input files. Functions with multiple return values are mapped to functions returning a struct.
    //export MyFunctionf
    func MyFunction(arg1, arg2 int, arg3 string) int64 {...}


    //export MyFunction2f
    func MyFunction2(arg1, arg2 int, arg3 string) (int64, *C.char) {...}
    they will be available in the C code as:
    extern int64 MyFunction(int arg1, int arg2, GoString arg3);

    extern struct MyFunction2_return MyFunction2(int arg1, int arg2, GoString arg3);

    2 、Go code may not store a Go pointer in C memory. C code may store Go pointers in C memory, subject to the rule above: it must stop storing the Go pointer when the C function returns.

      

  • 相关阅读:
    promethus监控JVM jar包
    ubuntu中文乱码解决办法
    IT焦躁中的赤子青年
    ftp neo4j http kafka搭建
    查看python脚本执行过程
    解决coredns-7f9c544f75-2sjs2一直处于ContainerCreating
    番茄工作法
    数据库的性能优化
    MyBatis
    CentOS下安装JDK,Tomcat,Redis,Mysql,及项目发布
  • 原文地址:https://www.cnblogs.com/xiaomayi-cyj/p/10348279.html
Copyright © 2011-2022 走看看