On Thursday, October 12, 2023 at 9:55:12 AM UTC-4 Ian Lance Taylor wrote:

On Thu, Oct 12, 2023 at 5:06 AM Pascal Costanza 
<pascal....@intel.com> wrote: 
> 
> I have a question about runtime.Pinner: The documentation states that you 
can only pin an object when it’s the result of calling new, taking the 
address of a composite literal, or taking the address of a local variable. 
> 
> At the same time, the Go language specification states that a slice 
created with make allocates a hidden array, and gives the example that 
make([]int, 50, 100) is the same as new([100]int)[0:50]. 
> 
> Taken together, this suggests that the following sequence should be 
correct: 
> 
> var p runtime.Pinner 
> s := make([]int, 100) 
> p.Pin(&s[0]) 
> 
> …since &s[0] can be understood as being the result of calling new. 
> 
> Is that intended? 

Yes.

I always figured it at least wasn't unintended and that's why this hasn't 
been some bug to be fixed. But it is also true that you can't just pass a 
slice or string directly to Pin, and IMO it's a bit strange as to why 
that's not allowed when &s[0] works. Perhaps I'm missing something.




> Also: I believe it would be good if the documentation would state that 
the zero value for type runtime.Pinner is ready to use. 

That's the general default behavior for types in the standard library. 
If nothing says otherwise, the zero value is ready to use. That said, 
I'm not opposed to mentioning it if someone wants to send a patch. 

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/d6157537-5e61-41f6-a5bc-6853c97ee67dn%40googlegroups.com.

Reply via email to