cgo透传字节流 c语言调用go语言 Posted on 2020-06-15 Edited on 2023-09-14 In Go语言基础 Views: 直接上代码: 1234567891011b := buf.Bytes()rc := C.the_function(unsafe.Pointer(&b[0]), C.int(buf.Len()))p := C.malloc(C.size_t(len(b)))defer C.free(p)// copy the data into the buffer, by converting it to a Go arraycBuf := (*[1 << 30]byte)(p)copy(cBuf[:], b)rc = C.the_function(p, C.int(buf.Len())) Post author: Tony Wang Post link: https://blog.aivgg.com/posts/143134662.html Copyright Notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.