Created
August 20, 2018 02:39
-
-
Save dulao5/c3926189a10f7579ada5befdd04e29a0 to your computer and use it in GitHub Desktop.
golang: slice append and cap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
slice := []int{1} | |
fmt.Printf("%v , len: %v , cap: %v\n", &slice[0], len(slice), cap(slice)) | |
oldCap := cap(slice) | |
for i := 0; i<10000; i++ { | |
slice = append(slice, i) | |
if cap(slice) > oldCap { | |
fmt.Printf("%v , len: %v , cap: %v\n", &slice[0], len(slice), cap(slice)) | |
oldCap = cap(slice) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output