Last active
August 29, 2015 14:04
-
-
Save xlab/f424553333847db9f4cf to your computer and use it in GitHub Desktop.
Convert c-array int32[] to go-slice []int32
This file contains hidden or 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 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