Created
September 24, 2013 03:03
-
-
Save nelhage/6679860 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "log" | |
func main() { | |
var a [128]byte | |
log.Printf("len(a) = %d", len(a)) | |
log.Printf("cap(a) = %d", cap(a)) | |
log.Printf("len(a[:10]) = %d", len(a[:10])) | |
log.Printf("cap(a[:10]) = %d", cap(a[:10])) | |
log.Printf("len(a[10:]) = %d", len(a[10:])) | |
log.Printf("cap(a[10:]) = %d", cap(a[10:])) | |
s := a[:10] | |
x := append(s, []byte("hi")...) | |
log.Printf("s = {%v, len=%d, cap=%d}", s, len(s), cap(s)) | |
log.Printf("x = {%v, len=%d, cap=%d}", x, len(x), cap(x)) | |
} | |
/* | |
[nelhage@anarchique:/tmp]$ ./slice | |
2013/09/23 22:55:02 len(a) = 128 | |
2013/09/23 22:55:02 cap(a) = 128 | |
2013/09/23 22:55:02 len(a[:10]) = 10 | |
2013/09/23 22:55:02 cap(a[:10]) = 128 | |
2013/09/23 22:55:02 len(a[10:]) = 118 | |
2013/09/23 22:55:02 cap(a[10:]) = 118 | |
2013/09/23 22:55:02 s = {[0 0 0 0 0 0 0 0 0 0], len=10, cap=128} | |
2013/09/23 22:55:02 x = {[0 0 0 0 0 0 0 0 0 0 104 105], len=12, cap=128} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment