Comments (1)
针对于 BytesToString
发现两个参考:
unsafe.String(unsafe.SliceData(b), len(b))
源自strings.Builder String()
unsafe.String(&b[0], len(b))
源自strings.Clone
个人也是倾向于后者,但这个确实对强迫症患者造成了一些纠结,哈哈。
不过需要注意使用后者的话,需要先判断长度
func BytesToString(b []byte) string {
if len(b) == 0 {
return ""
}
return unsafe.String(&b[0], len(b))
}
from go-questions.
Related Issues (20)
- 第三章:数据容器3.1.2-Page22 HOT 1
- 切片作为函数参数这一章节,倒数第三段描述应该不准确 HOT 1
- 垃圾回收机制图片错误
- go-questions/content/channel/7-操作 channel 的情况总结.md 文章内容有误 HOT 3
- 关于279页贴的Go仓库Issue HOT 1
- 请问一个关于 m 和主线程绑定的问题。(顺便提个 typo)
- 关于 P 的状态流转
- 步调算法下界描述有误
- 有关优雅关闭channel的问题
- 纸质版印刷图片展示不友好
- 《map的实现原理章节》关于slice的描述有点过时了
- 14.1.8 节
- 错误处理的As 和 Is 函数有误
- Page 288 (并发标记清除法的难点是什么)
- Page 289 关于写屏障 HOT 1
- go-questions/channel/graceful-close 文章内容疑似有误 HOT 1
- 1-map B=5时 bucket num 由 hash 的低 5 位决定
- 关于 Golang 内存分配机制 的延伸问题
- 《接口转换的原理》一节汇编过时
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-questions.