go memcpy
【摘要】 来源:https://github.com/jsgilmore/shm
callback := syscall.NewCallback(func(r uintptr, size int) (ret uintptr) { // 定义一个[]byte切片,用来存储C返回的字符串 t1 := time.Now() // get current time dat...
来源:https://github.com/jsgilmore/shm
-
callback := syscall.NewCallback(func(r uintptr, size int) (ret uintptr) {
-
-
// 定义一个[]byte切片,用来存储C返回的字符串
-
-
t1 := time.Now() // get current time
-
data := make([]byte,size)
-
C.memcpy(unsafe.Pointer(&data[0]), unsafe.Pointer(r), C.size_t(size))
-
package shm
-
-
//#include <string.h>
-
import "C"
-
import "unsafe"
-
-
func memcpy(dest, src []byte) int {
-
n := len(src)
-
if len(dest) < len(src) {
-
n = len(dest)
-
}
-
if n == 0 {
-
return 0
-
}
-
C.memcpy(unsafe.Pointer(&dest[0]), unsafe.Pointer(&src[0]), C.size_t(n))
-
return n
-
}
-
-
func memmove(dest, src []byte) int {
-
n := len(src)
-
if len(dest) < len(src) {
-
n = len(dest)
-
}
-
if n == 0 {
-
return 0
-
}
-
C.memmove(unsafe.Pointer(&dest[0]), unsafe.Pointer(&src[0]), C.size_t(n))
-
return n
-
}
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/88416455
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)