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

proposal: Go 2: bytes: remove NewBufferString #26281

Open
robpike opened this issue Jul 9, 2018 · 1 comment
Open

proposal: Go 2: bytes: remove NewBufferString #26281

robpike opened this issue Jul 9, 2018 · 1 comment

Comments

@robpike
Copy link
Contributor

@robpike robpike commented Jul 9, 2018

The constructor is often misused and confuses people. It can be used to put initial contents into a buffer that will be written into after, but so can buf.Write. Meanwhile, NewReader handles the case that most beginners misuse, calling NewBufferString when they only need NewBuffer.

This function's use case is not worth the confusion it causes and it should be deleted from the library.

@robpike robpike added the Go2 label Jul 9, 2018
@ianlancetaylor ianlancetaylor added this to the Go2 milestone Jul 9, 2018
@ianlancetaylor ianlancetaylor changed the title bytes: remove NewBufferString proposal: Go 2: bytes: remove NewBufferString Oct 2, 2018
@89z
Copy link

@89z 89z commented Dec 18, 2020

I was curious about this, as it seems to overlap with strings#NewReader. I
tried out these two files:

package main

import (
   "bytes"
   "strings"
   "time"
)

func main() {
   s := strings.Repeat("!", 999_999)
   bytes.NewBufferString(s)
   time.Sleep(time.Duration(time.Minute))
}
package main

import (
   "strings"
   "time"
)

func main() {
   s := strings.Repeat("!", 999_999)
   strings.NewReader(s)
   time.Sleep(time.Duration(time.Minute))
}

Here is what I got for memory use:

Function Kilobytes
bytes#NewBufferString 3,244
strings#NewReader 2,172

So if you only need to read, then seems like the strings function is the way to
go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants