// example1.go packge main func main() { s := make([]byte, 1024, 1024) _ = s }
s will be allocated in stack and lookup assembl <http://www.baidu.com/link?url=bAdrFLMvrfjd9qsjbYka0iztFO6qpJRgzpG6mzu9MrOtl8wUl4TmNVbQ19uYLjU75_lCRcNmRHuiocgN4N9QITmue5XAaqLYQOh9YQzpGi_>e code not call runtime.makeslice // example2.go packge main func main() { cap := 1024 s := make([]byte, 1024, cap) _ = s } s will be allocated in heap and lookup assemble code there is runtime.makeslice why this ??? // example3.go package main func main() { a := 100 if a>1 { a = 1000 } b := interface{}(a) _ = b } 0x0000 00000 (example1.go:3) TEXT "".main(SB), $64-0 0x0000 00000 (example1.go:3) MOVQ (TLS), CX 0x0009 00009 (example1.go:3) CMPQ SP, 16(CX) 0x000d 00013 (example1.go:3) JLS 93 0x000f 00015 (example1.go:3) SUBQ $64, SP 0x0013 00019 (example1.go:3) MOVQ BP, 56(SP) 0x0018 00024 (example1.go:3) LEAQ 56(SP), BP 0x001d 00029 (example1.go:3) FUNCDATA $0, gclocals·33cdeccccebe80329 f1fdbee7f5874cb(SB) 0x001d 00029 (example1.go:3) FUNCDATA $1, gclocals·33cdeccccebe80329 f1fdbee7f5874cb(SB) 0x001d 00029 (example1.go:8) MOVQ $1000, "".autotmp_0+48(SP) 0x0026 00038 (example1.go:8) MOVQ $0, "".autotmp_1+40(SP) 0x002f 00047 (example1.go:8) LEAQ type.int(SB), AX 0x0036 00054 (example1.go:8) MOVQ AX, (SP) 0x003a 00058 (example1.go:8) LEAQ "".autotmp_0+48(SP), AX 0x003f 00063 (example1.go:8) MOVQ AX, 8(SP) 0x0044 00068 (example1.go:8) LEAQ "".autotmp_1+40(SP), AX 0x0049 00073 (example1.go:8) MOVQ AX, 16(SP) 0x004e 00078 (example1.go:8) PCDATA $0, $0 0x004e 00078 (example1.go:8) CALL runtime.convT2E(SB) 0x0053 00083 (example1.go:10) MOVQ 56(SP), BP 0x0058 00088 (example1.go:10) ADDQ $64, SP 0x005c 00092 (example1.go:10) RET 0x005d 00093 (example1.go:10) NOP 0x005d 00093 (example1.go:3) CALL runtime.morestack_noctxt(SB) 0x0062 00098 (example1.go:3) JMP 0 lookup the assemble code and see the compiler is very clever to opt that but in example2.go why don't do this -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.