On Fri, 2018-09-28 at 08:14 +0200, Peter Mogensen wrote:
> 
> On 09/27/2018 11:12 PM, Dan Kortschak wrote:
> > 
> > Unless you are holding a real pointer to the value, they will have
> > no
> > root to hold them and so will by GC'd.
> Also if the pointer is returned by Pool.Get() ?
> That's probably one of the main questions here. Will an object from
> sync.Pool which have not been Put() be garbage collected if the
> reference is lost?

A value obtained from a sync.Pool is not special. The only things that
keep values alive as far as the GC is concerned is if they are attached
to a root. The root that holds things in the pool if they are there is
the global that is the pool. When you Get something from a pool, it no
longer holds it and so it's your job to look after it. If it is not
attached to a pointer value that you hold it is subject to collection

> > 
> > Further, the uintptr in the map
> > will not be updated if the value is moved (does not happen now but
> > may
> > in the future).
> !??!.... what?
> 
> Are you saying this statement from the Go spec is subject to change:
> "Pointer values are comparable. Two pointer values are equal if they
> point to the same variable or if both have value nil. Pointers to
> distinct zero-size variables may or may not be equal. "
> 
> ?

I don't understand what you are asking. First, uintptr is not a pointer
type, it's an integer type that is the same size as a pointer and that
can be interconverted with an unsafe.Pointer. If you hold a uintptr
that was converted from an unsafe.Pointer and you throw away the
unsafe.Pointer, you now have no pointer to the value you got from the
pool. The GC when it become a moving GC (if that happens) will need to
make sure pointers are adjusted when values move, but uintptr is not a
pointer, so it will not need to be adjusted.

What you are asking though is not related to what I wrote.

> > 
> > What you're doing here is unsafe.
> I know this involves the unsafe package.

OK, I'll restate, it's not just unsafe, it's catastrophically unsafe.
Unsafe can work, this won't.

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to