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: NewBuffer documentation error #27242

Closed
tebeka opened this issue Aug 26, 2018 · 4 comments
Closed

bytes: NewBuffer documentation error #27242

tebeka opened this issue Aug 26, 2018 · 4 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@tebeka
Copy link
Contributor

tebeka commented Aug 26, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/miki/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/miki/work/iguazio"
GOPROXY=""
GORACE=""
GOROOT="/opt/go"
GOTMPDIR=""
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build378279576=/tmp/go-build -gno-record-gcc-switches"

What did you do?

bytes.NewBuffer documentation says:

... It can also be used to size the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero.

However when I try to create such buffer and write more than the initial capacity - the buffer just grow.

See https://play.golang.org/p/-iCudrjewno

What did you expect to see?

An error or writer block

What did you see instead?

Buffer grows as much as needed.

@ALTree
Copy link
Member

ALTree commented Aug 26, 2018

An error or writer block

Why? That part of NewBuffer's documentation is talking about the initial capacity of the backing buffer.

Later on you call Write in a loop and Write is explicitly documented to grow the buffer as needed:

Write appends the contents of p to the buffer, growing the buffer as needed.

@ALTree
Copy link
Member

ALTree commented Aug 26, 2018

I mean we could change NewBuffer doc from

It can also be used to size the internal buffer for writing.

to

It can also be used to set the initial size of the internal buffer for writing.

to make completely clear that we're talking about the initial size, I guess...

@ALTree ALTree changed the title bytes.NewBuffer documentation error bytes: NewBuffer documentation error Aug 26, 2018
@ALTree ALTree added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Aug 26, 2018
@tebeka
Copy link
Contributor Author

tebeka commented Aug 27, 2018

@ALTree

It can also be used to set the initial size of the internal buffer for writing.

This seems great

@ALTree ALTree added this to the Go1.12 milestone Aug 29, 2018
@ALTree ALTree added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Aug 29, 2018
@gopherbot
Copy link

Change https://golang.org/cl/132035 mentions this issue: bytes: note that NewBuffer's initial size can grow

@golang golang locked and limited conversation to collaborators Aug 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants