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: document bytes.Buffer reuse after .Reset #13671

Closed
sidnei opened this issue Dec 18, 2015 · 3 comments
Closed

bytes: document bytes.Buffer reuse after .Reset #13671

sidnei opened this issue Dec 18, 2015 · 3 comments

Comments

@sidnei
Copy link

sidnei commented Dec 18, 2015

I'd expect that after calling .Reset() the bytes array returned by a previous call to .Bytes() would never be modified. Alas, not the case.

http://play.golang.org/p/ERqoY7_PMG

@dsnet
Copy link
Member

dsnet commented Dec 18, 2015

I think this is working as intended. The purpose of Buffer.Reset is for performance purposes such that we don't allocate a new underlying buffer. This, however, implies that bt1 and bt2 share the same underlying byte slice and thus makes sense why the second write affects the first.

Though, I do believe that the documentation for Buffer.Reset or Buffer.Truncate could probably make this more clear.

@ianlancetaylor ianlancetaylor changed the title bytes.Buffer reuse after .Reset() bytes: document bytes.Buffer reuse after .Reset Dec 18, 2015
@ianlancetaylor ianlancetaylor added this to the Go1.6Maybe milestone Dec 18, 2015
@ianlancetaylor
Copy link
Contributor

This is working as intended but the docs could be clearer.

@gopherbot
Copy link

CL https://golang.org/cl/18029 mentions this issue.

@rsc rsc closed this as completed in 5270b57 Dec 18, 2015
@golang golang locked and limited conversation to collaborators Dec 29, 2016
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