Skip to content

Instantly share code, notes, and snippets.

@enginespot
Forked from nasitra/carray2slice.go
Created June 25, 2021 09:14
Show Gist options
  • Save enginespot/be9ddc5ce30e5d7c738ff60fb8858893 to your computer and use it in GitHub Desktop.
Save enginespot/be9ddc5ce30e5d7c738ff60fb8858893 to your computer and use it in GitHub Desktop.
Convert 'C' array to golang slice
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