How to enlarge a fragment by adding? Is the capacity always doubled?

When the appendslice, the slice can be increased, if necessary. Since spec does not specify an algorithm, this is interesting to me.

I am trying to find an implementation appendin the Go source code but cannot find it.

Can someone explain the indicated algorithm to enlarge the fragment? Is the capacity always doubled? or can anyone indicate the location of the source code append? I can check it out myself.

+4
source share
1 answer

The code responsible for growing fragments in appendcan be found here.

So, in the current implementation, the following rules:

  • , ​​ .
  • , 1024, 25%, . , .

, , , .

+6

Source: https://habr.com/ru/post/1539689/


All Articles