CGO Wiki: https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices This explains how to convert the c arrays into go slices (without copying the original data) and it also makes a statement: "It is important to keep in mind that the Go garbage collector will not interact with this data, and that if it is freed from the C side of things, the behavior of any Go code using the slice is nondeterministic."
But my doubt is, after we are done using this slice, how do we free the memory allocated for the slice? the backing C array can be freed by appropriate calls to the C world, but what about the slice? will it be garbage collected?
Also,
slice := (*[1 << 28]C.YourType)(unsafe.Pointer(theCArray))[:length:length]
will this statement allocate a pretty big array and then slice? I mean, will it cause a BIG memory allocation? if so, how and when will that BIG memory be freed?
it is also confusing to understand that the slice will be 'backed by the C array'.
if the slice is backed by the C array, then why is a BIG array [1<<28]
required?