英文:
Why Golang hchan struct closed field use uint32 type?
问题
type hchan struct {
qcount uint // 队列中的总数据量
dataqsiz uint // 循环队列的大小
buf unsafe.Pointer // 指向包含dataqsiz个元素的数组
elemsize uint16
closed uint32
....
我搜索了所有closed
字段的引用,其值只有0和1。更令人困惑的是为什么不使用int8或其他类型?😕
英文:
type hchan struct {
qcount uint // total data in the queue
dataqsiz uint // size of the circular queue
buf unsafe.Pointer // points to an array of dataqsiz elements
elemsize uint16
closed uint32
....
I searched the references of all closed
fields, the values are only 0 and 1. What is more confusing is why not use int8 or other types?😝
答案1
得分: 3
为什么Golang中的hchan结构的closed字段使用uint32类型而不是uint8类型?
请自问:
- 使用uint8会有什么好处?(提示:没有)
- 使用uint8会使代码更复杂吗?(提示:是的)
有时候没有“深层次”的原因。uint32运行良好并且很好。
英文:
> Why Golang hchan struct closed field use uint32 type [instead of uint8]?
Ask yourself:
- What would be gained by using uint8? (Hint: nothing)
- Would using uint8 make the code more complicated? (Hint: yes)
Sometimes there are no "deep" reasons. uint32 works well and is fine.
答案2
得分: 0
问问自己:
- 你想要实现什么目标?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论