We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
参考资料:
golang-string 和 bytes 之间的 unsafe 转换
How to use unsafe get a byte slice from a string without memory copy
How to efficiently concatenate strings in go
[zy] - strings.Builder的Reset()方法与bytes.Buffer的Reset()方法不同:
strings.Builder
Reset()
bytes.Buffer
string
String()
The text was updated successfully, but these errors were encountered:
如果需要使用sync.Pool复用的话,应该还是结合bytes.Buffer一起使用会更好。
sync.Pool
Sorry, something went wrong.
No branches or pull requests
参考资料:
golang-string 和 bytes 之间的 unsafe 转换
How to use unsafe get a byte slice from a string without memory copy
How to efficiently concatenate strings in go
[zy] -
strings.Builder
的Reset()
方法与bytes.Buffer
的Reset()
方法不同:strings.Builder
只是解除了跟底层数据的绑定关系。源码bytes.Buffer
是复用了底层数据。strings.Builder
不复用底层的数据呢。是因为:strings.Builder
在做string
转换的时候做了优化,具体参考:Why doesn't string.Builder Reset() preserve the underlying buffer?。它返回出去的字符串,仍然在复用底层的地址。相当于它的优化点在于String()
函数。bytes.Buffer
的String()是复制一块内存,相当于做了一层内存拷贝。The text was updated successfully, but these errors were encountered: