You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
changed the title
bytes.Buffer reuse after .Reset()
bytes: document bytes.Buffer reuse after .Reset
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
The text was updated successfully, but these errors were encountered: