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.

      

  • 相关阅读:
    Redis 集群搭建详细指南
    java 获取properties的几种方式
    redis主从,哨兵集群
    Nginx服务器之负载均衡策略
    Redis中常用命令
    Java中使用Jedis操作Redis
    redis学习教程网站
    Redis 数据备份与恢复
    CentOS6.5 在线安装Redis5.0.9
    nginx中文学习网站(推荐)
  • 原文地址:https://www.cnblogs.com/xiaomayi-cyj/p/10348279.html
Copyright © 2011-2022 走看看