package main
import "fmt"
/*
* Append will reallocate the underlying array if needed, increasing the
* capacity. As you can see, the capacity here doubles each time (though
* I suppose the exact amount is an implementation issue). This is a
* typical approach, which makes the number of reallocations log n for
* n increments, while wasting less than 1/2 of the allocated space.
*/
func main() {
sl := make([]int,0)
for i := 0; i < 300 ; i++ {
fmt.Printf("length = %d, capacity = %d\n", len(sl), cap(sl))
sl = append(sl, i)
}
fmt.Printf("length = %d, capacity = %d\n", len(sl), cap(sl))
}