-
-
Save enginespot/be9ddc5ce30e5d7c738ff60fb8858893 to your computer and use it in GitHub Desktop.
Convert 'C' array to golang slice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func carray2slice(array *C.int, len int) []C.int { | |
var list []C.int | |
sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&list))) | |
sliceHeader.Cap = len | |
sliceHeader.Len = len | |
sliceHeader.Data = uintptr(unsafe.Pointer(array)) | |
return list | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment