On Thursday, October 12, 2023 at 8:07:02 AM UTC-4 Pascal Costanza wrote:
Hi, 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. I think that's not quite following the spirit of the documentation, but as you point out, it's already possible to pin (and call runtime.SetFinalizer) on memory that doesn't strictly follow the documentation. It's even possible to pin strings, but it requires unsafe.StringData (or something similar). I'm of the opinion that we should broaden the scope of runtime.Pinner at least slightly, to allow for things like slices and strings explicitly. Sometime soon I'll file a proposal about this since it's very technically an API change. In the same vein, the cgo pointer passing rules have some restrictions that I'm not sure are necessary, but I'm concerned that I may be missing something subtle and I haven't had the time to think about it more thoroughly. (All of this stuff is pretty subtle.) Is that intended? 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 is a good point. I'll send a doc change for that. Thanks, Pascal -- 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/1b14537e-e4a8-4091-9a23-132c5b599a87n%40googlegroups.com.