Skip to content

Instantly share code, notes, and snippets.

View ha7sh17's full-sized avatar

Han Shin ha7sh17

View GitHub Profile
@jamesandersen
jamesandersen / cgo_memory_alloc.go
Created June 30, 2017 23:05
Allocating C memory when invoking C code via CGO
// allocate 81 char string in C memory
parsed := C.CString(strings.Repeat("0", 81))
defer C.free(unsafe.Pointer(parsed)) // free it when we're done here
// allocate byte array for our image data in C memory
p := C.CBytes(data)
defer C.free(unsafe.Pointer(p)) // free it when we're done
// float32 is standardized type compatible with C
gridCoords := []float32{-1, -1, -1, -1, -1, -1, -1, -1}