Unless, the C function stores the pointer and it's kept after the call 
returns, correct? That's what I mean by calling the function 
keep_this_pointer in the second example. In this case, it would be 
necessary, I'm assuming?

Julio
On Monday, July 8, 2024 at 11:56:30 PM UTC+2 Ian Lance Taylor wrote:

> On Mon, Jul 8, 2024 at 12:38 PM Antonio Caceres Cabrera
> <julioca...@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/b3b3a36b-87ba-4271-b004-810670eb759an%40googlegroups.com.

Reply via email to