golang.org/toolchain@v0.0.1-go1.9rc2.windows-amd64/blog/content/slices/prog090.go (about)

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