1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| type student struct { name string }
func stackSpace() { length := 10 space1 := make([]int, length) for i := 0; i < len(space1); i++ { space1[i] = i } len1 := unsafe.Sizeof(space1) fmt.Println("space1 length:", len1)
space2 := make([]int, 100, 100) for i := 0; i < len(space2); i++ { space2[i] = i } len2 := unsafe.Sizeof(space2) fmt.Println("space2 length:", len2)
space3 := make([]int32, 8192*2+1, 8192*2+1) for i := 0; i < len(space3); i++ { space3[i] = int32(i) } len3 := unsafe.Sizeof(space3) fmt.Println("space3 length:", len3)
space4 := make([]int64, 8193, 8193) for i := 0; i < len(space4); i++ { space4[i] = int64(i) } len4 := unsafe.Sizeof(space4) fmt.Println("space4 length:", len4)
space5 := make([]string, 4097, 4097) for i := 0; i < len(space5); i++ { s := "a" space5[i] = s } len5 := unsafe.Sizeof(space5) fmt.Println("space5 length:", len5)
space6 := make([]*string, 8193, 8193) for i := 0; i < len(space6); i++ { s := "abc" space6[i] = &s } len6 := unsafe.Sizeof(space6) fmt.Println("space6 length:", len6)
space7 := make([]student, 4097, 4097) for i := 0; i < len(space7); i++ { space7[i].name = "abc" } len7 := unsafe.Sizeof(space7) fmt.Println("space7 length:", len7) }
|