Skip to content

Instantly share code, notes, and snippets.

@NickNaso
Forked from nasitra/carray2slice.go
Created November 19, 2019 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickNaso/c7e01ae554057d9c682c6e3bfb600bd1 to your computer and use it in GitHub Desktop.
Save NickNaso/c7e01ae554057d9c682c6e3bfb600bd1 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