Skip to content

Instantly share code, notes, and snippets.

@xlab
Last active August 29, 2015 14:04
Show Gist options
  • Save xlab/f424553333847db9f4cf to your computer and use it in GitHub Desktop.
Save xlab/f424553333847db9f4cf to your computer and use it in GitHub Desktop.
Convert c-array int32[] to go-slice []int32
func arrayToSliceInt32(ptr unsafe.Pointer, size int) (ints []int32) {
hdr := reflect.SliceHeader{
Data: uintptr(ptr),
Len: size,
Cap: size,
}
cints := *(*[]int32)(unsafe.Pointer(&hdr))
ints = make([]int32, size)
// TODO: bech this
copy(ints, cints)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment