Hi Gophers,
I'm trying to use cgo for a C library, specifically a function which takes
a void pointer to a buffer, and I'm trying to pass a Go-Slice as this
buffer.
```
func Write(buf []byte) (int, error) {
// var pin rumtime.Pinner
// pin.Pin(&buf[0])
// defer pin.Unpin()
// is this necessary? Is it even safe?
...
ret := C.lib_read(unsafe.Pointer(&buf[0]), C.int(len(buf))) // function
which reads from this buffer
...
}
```
Does this require explicit pinning of buf? And if so, is the commented part
a valid pinning of a slice? The documentation states that pointers passed
to C functions are implicitly pinned (on the top-level that is), but does
this also apply to slices, i.e. if I pass a (unsafe) pointer to the first
element, is the slice's entire backing array implicitly pinned?
I know that there are some runtime checks for this, but I am worried that
any use of unsafe.Pointer might perhaps override these checks completely.
Thanks a lot.
Julio
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/d3bf9a5d-50dd-4c1c-9f5e-4f7d3f7a3d0cn%40googlegroups.com.