On Mon, Jul 8, 2024 at 12:38 PM Antonio Caceres Cabrera <juliocacerc...@gmail.com> wrote: > > Sorry, accidentally hit the wrong response button, so I'm posting it again: > > Thanks for the clarification, Ian. > > Is it also possible to pin memory to local go-arrays? > The docs state > >Go values created by calling new, by taking the address of a composite > >literal, or by taking the address of a local variable may also have their > >memory pinned using runtime.Pinner. > > In this example: > ``` > var pin runtime.Pinner > var buf [32]byte > pin.Pin(&buf[0]) > C.keep_this_pointer(&buf[0]) > ``` > > Is this ok since it counts as taking the address of a local variable or would > the array have to be created with `new([32]byte)` ?
Yes, this is an example of taking the address of a local variable. The runtime.Pinner is not required here. In general a runtime.Pinner is only required when passing the address of a value that itself contains Go pointers. In that case the internal Go pointers need to be explicitly pinned. Ian -- 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 golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUL2voFfmY4QnLpod-HdguppGd0eeuWpwJrM9ak4ckPaA%40mail.gmail.com.