github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/blog/content/slices/prog080.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  )
    10  
    11  func main() {
    12  	slice := make([]int, 10, 15)
    13  	fmt.Printf("len: %d, cap: %d\n", len(slice), cap(slice))
    14  	newSlice := make([]int, len(slice), 2*cap(slice))
    15  	for i := range slice {
    16  		newSlice[i] = slice[i]
    17  	}
    18  	slice = newSlice
    19  	fmt.Printf("len: %d, cap: %d\n", len(slice), cap(slice))
    20  	// OMIT
    21  }