mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 12:59:23 +08:00
684110bc9a
* Avoid to copy during converting C bytes to Go bytes Signed-off-by: yah01 <yah2er0ne@outlook.com> * Add BytesConverter to achieve no-copy converting C bytes to Go bytes Signed-off-by: yah01 <yah2er0ne@outlook.com>
20 lines
301 B
Go
20 lines
301 B
Go
package cgoconverter
|
|
|
|
/*
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
*/
|
|
import "C"
|
|
import "unsafe"
|
|
|
|
func copyToCBytes(data []byte) unsafe.Pointer {
|
|
return C.CBytes(data)
|
|
}
|
|
|
|
func mallocCBytes(v byte, len int) unsafe.Pointer {
|
|
p := C.malloc(C.ulong(len))
|
|
C.memset(p, C.int(v), C.ulong(len))
|
|
|
|
return p
|
|
}
|