Re: [go-nuts] Computing a hash over a uintptr ?

2021-06-04 Thread Ian Lance Taylor
On Fri, Jun 4, 2021 at 10:00 AM Robert Engels wrote: > > I was thinking of using C.malloc to create off heap structures. The uintptr > to those structs should be stable and can be used as map keys or values, > right? > > Not suggesting anyone should do that - just feasibility. Yes, that works

Re: [go-nuts] Computing a hash over a uintptr ?

2021-06-04 Thread Robert Engels
I was thinking of using C.malloc to create off heap structures. The uintptr to those structs should be stable and can be used as map keys or values, right? Not suggesting anyone should do that - just feasibility. > On Jun 4, 2021, at 10:38 AM, Ian Lance Taylor wrote: > > On Fri, Jun 4,

Re: [go-nuts] Computing a hash over a uintptr ?

2021-06-04 Thread Ian Lance Taylor
On Fri, Jun 4, 2021 at 5:23 AM Robert Engels wrote: > > I was referring to the “special cases” in this section > https://golang.org/cmd/cgo/ - wouldn’t all of these uintptr be stable? The cgo tool gets special treatment: each cgo call is permitted to pin a known number of pointers. There is

Re: [go-nuts] Computing a hash over a uintptr ?

2021-06-04 Thread Jan Mercl
On Fri, Jun 4, 2021 at 3:02 PM christoph...@gmail.com wrote: > > That is true in current implementations, but Go, the language, does not > > guarantee that pointers will never move. > > That is what I thought, but it is allowed to use a pointer far map keys. And > I have seen some

Re: [go-nuts] Computing a hash over a uintptr ?

2021-06-04 Thread 'Axel Wagner' via golang-nuts
No, because the Garbage Collector knows that they are pointers and would change the pointer in the map (and presumably its bucket) if it moved the value. It's certainly not trivial to implement, but these are problems that would have to be solved if the GC starts moving things around - because the

Re: [go-nuts] Computing a hash over a uintptr ?

2021-06-04 Thread christoph...@gmail.com
> That is true in current implementations, but Go, the language, does not guarantee that pointers will never move. That is what I thought, but it is allowed to use a pointer far map keys. And I have seen some programs/package using this feature. Apparently all these programs and packages

Re: [go-nuts] Computing a hash over a uintptr ?

2021-06-04 Thread Robert Engels
I was referring to the “special cases” in this section https://golang.org/cmd/cgo/ - wouldn’t all of these uintptr be stable? > On Jun 4, 2021, at 12:25 AM, Ian Lance Taylor wrote: > > On Thu, Jun 3, 2021 at 9:13 PM Robert Engels wrote: >> >> Doesn’t that depend on what the uintptr refers

Re: [go-nuts] Computing a hash over a uintptr ?

2021-06-03 Thread Ian Lance Taylor
On Thu, Jun 3, 2021 at 9:13 PM Robert Engels wrote: > > Doesn’t that depend on what the uintptr refers to? Eg if it was allocated off > heap to begin with then it should be stable and computing a hash on it is > valid. That is true in current implementations, but Go, the language, does not

Re: [go-nuts] Computing a hash over a uintptr ?

2021-06-03 Thread Robert Engels
Doesn’t that depend on what the uintptr refers to? Eg if it was allocated off heap to begin with then it should be stable and computing a hash on it is valid. > On Jun 3, 2021, at 9:42 AM, 'Axel Wagner' via golang-nuts > wrote: > >  >> On Thu, Jun 3, 2021 at 4:19 PM christoph...@gmail.com

Re: [go-nuts] Computing a hash over a uintptr ?

2021-06-03 Thread 'Axel Wagner' via golang-nuts
On Thu, Jun 3, 2021 at 4:19 PM christoph...@gmail.com < christophe.mees...@gmail.com> wrote: > The documentation doesn’t specify that we can cast an uintptr into a > uint64. > Both are integer types, so they can be converted. You might be worried about their respective sizes and you are correct

[go-nuts] Computing a hash over a uintptr ?

2021-06-03 Thread christoph...@gmail.com
The documentation specifies that a pointer can be cast into a uintptr integer. I assume that the uintptr is ignored by the garbage collector. I would like to compute a hash over the uintptr. How do I achieve that ? The documentation doesn’t specify that we can cast an uintptr into a uint64.