-
-
Save jbowens/30f0854e7e5cec46cce5e2d78ec2c943 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 ( | |
"bytes" | |
"fmt" | |
) | |
func main() { | |
functionWithBuffer() | |
} | |
func functionWithBuffer() { | |
var buf bytes.Buffer | |
for i := 0; i < 100; i++ { | |
buf.WriteByte(byte(i)) | |
} | |
fmt.Println(buf.Len()) | |
} |
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 ( | |
"bytes" | |
"fmt" | |
) | |
func main() { | |
functionWithBuffer() | |
} | |
func functionWithBuffer() { | |
buf := new(bytes.Buffer) | |
for i := 0; i < 100; i++ { | |
buf.WriteByte(byte(i)) | |
} | |
fmt.Println(buf.Len()) | |
} |
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
jackson@mba ~/src/scratch/goescape $ go build -gcflags '-m' a.go | |
# command-line-arguments | |
./a.go:17:21: inlining call to bytes.(*Buffer).Len | |
./a.go:15:6: buf escapes to heap | |
./a.go:13:6: moved to heap: buf | |
./a.go:17:21: buf.Len() escapes to heap | |
./a.go:17:21: functionWithBuffer buf does not escape | |
./a.go:17:13: functionWithBuffer ... argument does not escape | |
jackson@mba ~/src/scratch/goescape $ go build -gcflags '-m' b.go | |
# command-line-arguments | |
./b.go:17:21: inlining call to bytes.(*Buffer).Len | |
./b.go:13:12: new(bytes.Buffer) escapes to heap | |
./b.go:17:21: buf.Len() escapes to heap | |
./b.go:17:13: functionWithBuffer ... argument does not escape |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment