FAQ
Hi,

What function does golang use to grow the capacity of slices initialized
with 0 len and cap during make ?
i.e
   s := make([]int,0)

intially capacity is 0,

As i append elements, the capacity seems to grow in powers of 2 . Beyond
1024 , it is not powers of 2.

Can you please tell me what function is used to grow the capacity ?


Thanks
Prakash

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

Search Discussions

  • Josh Bleecher Snyder at May 18, 2015 at 3:38 pm

    What function does golang use to grow the capacity of slices initialized
    with 0 len and cap during make ?
    i.e
    s := make([]int,0)

    intially capacity is 0,

    As i append elements, the capacity seems to grow in powers of 2 . Beyond
    1024 , it is not powers of 2.

    Can you please tell me what function is used to grow the capacity ?
    runtime.growslice, which is inserted as needed by the compiler.
    https://github.com/golang/go/blob/master/src/runtime/slice.go#L36

    -josh

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 18, '15 at 3:34p
activeMay 18, '15 at 3:38p
posts2
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase