Re: [go-nuts] Is the GC recovering storage when full slice expression reduce capacity ?

2020-01-13 Thread Keith Randall
It can get expensive to do that. Instead of just a mark bit per object, and a queue of pointers to mark, you need a mark bit per word and a queue of ptr+len. You can also end up doing more than constant work per mark. x := [10]*int{ ... 10 pointers ... } a := x[:3:3] b := x[7::] x is now dead,

Re: [go-nuts] Is the GC recovering storage when full slice expression reduce capacity ?

2020-01-13 Thread Jan Mercl
On Sat, Jan 11, 2020 at 4:43 AM wrote: >> But there's one guarantee - the "dead" slice portion after >> cap will not be scanned by the collector if no other live object uses >> it. > > > That's not correct. If there is a reference to an object, the entire object > is live and is scanned,

Re: [go-nuts] Is the GC recovering storage when full slice expression reduce capacity ?

2020-01-10 Thread keith . randall
On Friday, January 10, 2020 at 1:02:22 AM UTC-8, Jan Mercl wrote: > > On Fri, Jan 10, 2020 at 9:52 AM Christophe Meessen > > wrote: > > > > It is possible to reduce the capacity of a slice by using the full slice > expression (https://golang.org/ref/spec#Slice_expressions). > > > > Now

Re: [go-nuts] Is the GC recovering storage when full slice expression reduce capacity ?

2020-01-10 Thread Jan Mercl
On Fri, Jan 10, 2020 at 9:52 AM Christophe Meessen wrote: > > It is possible to reduce the capacity of a slice by using the full slice > expression (https://golang.org/ref/spec#Slice_expressions). > > Now consider the following code where a is a 1MB slice. I then create b, a > slice of a, but

[go-nuts] Is the GC recovering storage when full slice expression reduce capacity ?

2020-01-10 Thread Christophe Meessen
It is possible to reduce the capacity of a slice by using the full slice expression (https://golang.org/ref/spec#Slice_expressions). Now consider the following code where a is a 1MB slice. I then create b, a slice of a, but with a much smaller capacity. Finally, I change the value of a so that