On Sun, Sep 5, 2021 at 1:34 PM 'Dan Kortschak' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> On Sun, 2021-09-05 at 13:09 +0200, 'Axel Wagner' via golang-nuts wrote:
> > This sounds interesting, but I don't understand it. Would you be
> > willing to expand on this?
>
> It's a consequence of the sum of successive powers of two. To have
> reached an allocation of 2^n slots assuming a doubling n times you must
> have deallocated and moved 2^n-1 total slots \sum(2^0, 2^1, 2^2, ...,
> 2^(n-1)). This is less than the amount of space that you are using now,
> by one slot, so by definition you will not be able to use any of that
> space.


Nifty. Good to learn new things :) There is a discussion here, which
justifies the use of φ, somewhat convincingly:
https://archive.li/Z2R8w

Does Go use this? Naively, the way `append` works we can't re-use the
storage anyway (as it might be aliased by a different slice), so ISTM doing
this would require at least cooperation from the compiler to do alias
analysis and make sure we are not keeping the slice around elsewhere. It
*seems* like a sort of optimization Go doesn't do, but you would know
better, I think.


> Note that here "slots" is any arbitrary number of contiguous
> bytes.
>
> This is pessimistic and only deals with allocations associated with a
> single growing array, discounting the possibility of recovering from
> unused allocations elsewhere.
>
>
> --
> 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/ba45f293129926415fa8e83c53d680f53bb009c7.camel%40kortschak.io
> .
>

-- 
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/CAEkBMfFmfQEgjF5FgCbQKCvPSGKbczZZ3Ac5RdSaH7%2BYT90LeA%40mail.gmail.com.

Reply via email to