On Sat, Sep 4, 2021 at 7:15 PM Miraddo <mposhtd...@gmail.com> wrote:

> Hey Guys,
>
> We know slices grow by doubling until size 1024, the capacity will grow at
> 25%. The question that I had was why after 1024 elements? Why didn't the
> developers chose another number like 2048 or other numbers?
>

I suspect: No reason. Someone probably ran some benchmarks and 1024 seemed
like a decent enough number. Maybe not even that.

There is no algorithmic reason to switch - as long as the growth is
geometric (i.e. the factor between growth-stages is a constant), you get
the desired amortized constant cost of append. Whether that factor is 2 or
1.25 doesn't matter. It's just a bit of an optimization to make it 2 for
small values - it doesn't terribly matter what's "small" for this heuristic.


>
> Thanks,
> Milad
>
> --
> 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/21a5a2b5-2eaf-45d6-a538-5a882fafd0a6n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/21a5a2b5-2eaf-45d6-a538-5a882fafd0a6n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAEkBMfHMAyp-6AcVBnV9AbkY_kAO_Z5h-AJMwph345_0Gqq8ww%40mail.gmail.com.

Reply via email to