On Thu, Jul 18, 2019 at 8:35 AM Andrey Tcherepanov
<xnow4fippy...@sneakemail.com> wrote:
>
> > Basically, it's hard to be sure that there isn't any other slice somewhere 
> > that might permit references to that trailing memory
>
> Ian, I am kind of curious about this case. I understand that "hard" is not 
> "impossible", but still - if I copy the needed part to a smaller array, how 
> does the GC knows that there are no more slices pointing to a part of an old 
> allocation?

I'm not sure precisely what you are asking.  Conceptually, the GC
starts with global variables and goroutine stacks and traces all
pointers to find all reachable memory.  Unreachable memory is
discarded.

What makes this case harder is that we need to not only track
pointers, we need to also look at the slice information to turn the
pointer to the backing array into a sort of bounded pointer: a pointer
to only part of the object, not all of it.  That means that the GC has
to understand slice structures, which are more complex than pointers.
It means that the compiler has to build slice structures in a way that
the GC can understand, which it currently does not do.  That may sound
simple, but currently the compiler splits up local slices into three
independent local variables, and that would either become impossible
or would require significantly more data to be recorded for the GC.

Another wrinkle is that the current memory allocator does not support
shrinking memory allocations at all, since that currently never
happens.  The allocator is based on storing objects of the same size
together, so it's not easy to split an existing object into smaller
sizes.  That said, very large objects do have to be handled
differently and it might be more feasible to shrink those objects; I'm
not sure.

So those are some of the reasons why it is hard.

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

Reply via email to