# just-for-fun/escape .\main.go:8:6: can inline (*Dog).Eat as: method(*Dog) func() { } .\main.go:30:6: cannot inline noneEscape: marked go:noinline .\main.go:31:7: inlining call to (*Dog).Eat method(*Dog) func() { } .\main.go:26:6: cannot inline nop: marked go:noinline .\main.go:35:6: cannot inline escape: marked go:noinline .\main.go:15:6: cannot inline main: function too complex: cost 355 exceeds budget 80 .\main.go:8:7: (*Dog).Eat d does not escape .\main.go:30:17: noneEscape d does not escape .\main.go:26:11: nop a does not escape .\main.go:35:13: leaking param: a .\main.go:35:13: from a.Eat() (receiver in indirect call) at .\main.go:36:7 .\main.go:20:8: dog2 escapes to heap .\main.go:20:8: from dog2 (passed to call[argument escapes]) at .\main.go:20:8 .\main.go:19:13: new(Dog) escapes to heap .\main.go:19:13: from dog2 (assigned) at .\main.go:19:7 .\main.go:19:13: from dog2 (interface-converted) at .\main.go:20:8 .\main.go:19:13: from dog2 (passed to call[argument escapes]) at .\main.go:20:8 .\main.go:22:14: &dog3 escapes to heap .\main.go:22:14: from ... argument (arg to ...) at .\main.go:22:13 .\main.go:22:14: from *(... argument) (indirection) at .\main.go:22:13 .\main.go:22:14: from ... argument (passed to call[argument content escapes]) at .\main.go:22:13 .\main.go:22:14: &dog3 escapes to heap .\main.go:22:14: from &dog3 (interface-converted) at .\main.go:22:14 .\main.go:22:14: from ... argument (arg to ...) at .\main.go:22:13 .\main.go:22:14: from *(... argument) (indirection) at .\main.go:22:13 .\main.go:22:14: from ... argument (passed to call[argument content escapes]) at .\main.go:22:13 .\main.go:21:2: moved to heap: dog3 .\main.go:16:13: main new(Dog) does not escape .\main.go:18:5: main dog1 does not escape .\main.go:22:13: main ... argument does not escape <autogenerated>:1: leaking param: .this <autogenerated>:1: from .this.Eat() (receiver in indirect call) at <autogenerated>:1
funcstringtoslicebyte(buf *tmpBuf, s string) []byte { var b []byte // 如果buf不为空,并且len(buf)小于len(s),会直接使用buf作为底层数组,而buf的长度为32 if buf != nil && len(s) <= len(buf) { *buf = tmpBuf{} b = buf[:len(s)] } else { b = rawbyteslice(len(s)) } copy(b, s) return b }
// rawbyteslice allocates a new byte slice. The byte slice is not zeroed. funcrawbyteslice(size int)(b []byte) { cap := roundupsize(uintptr(size)) p := mallocgc(cap, nil, false) ifcap != uintptr(size) { memclrNoHeapPointers(add(p, uintptr(size)), cap-uintptr(size)) }