Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bytes: bytes.Buffer always escapes to heap #7661

Closed
lukescott opened this issue Mar 28, 2014 · 3 comments
Closed

bytes: bytes.Buffer always escapes to heap #7661

lukescott opened this issue Mar 28, 2014 · 3 comments
Milestone

Comments

@lukescott
Copy link

Even with a bytes.Buffer less than 64 bytes the Buffer always gets allocated to the
heap. I was quite surprised by this as bytes.Buffer contains "bootstrap
[64]byte" which is supposed to prevent this. Is that correct?

What does 'go version' print?

go version go1.2.1 darwin/amd64
go version devel +773ba5ac4f21 Fri Mar 28 11:30:02 2014 -0400 darwin/amd64

What steps reproduce the problem?

I've distilled the code in test.go

test.go: http://play.golang.org/p/DLzkUIN4a6

$ go build -gcflags=-m test.go

What happened?

# command-line-arguments
./test.go:8: can inline (*Buffer).Grow
./test.go:15: inlining call to (*Buffer).Grow
./test.go:9: b.bootstrap escapes to heap
./test.go:8: leaking param: b
./test.go:8: leaking param: b
./test.go:15: b.bootstrap escapes to heap
./test.go:14: moved to heap: myBuf
./test.go:15: myBuf escapes to heap

What should have happened instead?

b.bootstrap and myBuf should not escape to the heap

Please provide any additional information below.

This happens in Go 1.2.1 and tip.
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Apr 3, 2014

Comment 2:

bootstrap is just meant to reduce the number of allocations, not to keep anything on the
stack.

Status changed to WorkingAsIntended.

@lukescott
Copy link
Author

Comment 3:

Ok just out of curiosity and future reference, in the case of the linked example, why
does bootstrap escape to the heap?

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants