Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于切片cap的扩容 #6

Open
cx4 opened this issue May 20, 2019 · 0 comments
Open

关于切片cap的扩容 #6

cx4 opened this issue May 20, 2019 · 0 comments

Comments

@cx4
Copy link

cx4 commented May 20, 2019

func main() { scores := make([]int, 0, 5) c := cap(scores) fmt.Println(c) for i := 0; i < 25; i++ { scores = append(scores, i) // 如果容量已经改变,go为了容下这些新数据,不得不增长数组的长度 if cap(scores) != c { c = cap(scores) fmt.Println(c) } } }
看到文章写的是,扩容三次5、10、20
但是代码实际执行的时候是6、24、48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant