go - 为什么 Golang hchan struct 封闭字段使用 uint32 类型?
问题描述
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
....
我搜索了所有closed
字段的引用,值只有0和1。更令人困惑的是为什么不使用int8或其他类型?
解决方案
为什么 Golang hchan struct 封闭字段使用 uint32 类型 [而不是 uint8]?
问你自己:
- 使用 uint8 会得到什么?(提示:无)
- 使用 uint8 会使代码更复杂吗?(提示:是的)
有时没有“深层”原因。uint32 运行良好并且很好。
推荐阅读
- algorithm - 在方法中找到描述递归的公式
- vb.net - 与类共享值并通过属性返回值
- redis - 当我运行“redis-server --service-start”时,出现错误代码 1056“启动服务失败:未知错误”
- python - ConfigParser 没有属性
- java - Spring Boot OIDC客户端开发通过VS代码不起作用
- android - AlarmManager 每 20 秒触发一次,而不是使用给定的时间间隔
- c++ - C++ 将字符从一个向量移动到另一个向量
- javascript - 无法为此模块构建类型化接口:createFragmentRef
- node.js - Requestlist 在 apify 中为超过 1000 万个 wordlist 抛出堆内存不足
- c++ - “std::string(*)[3][5][30]”类型的 C++ 参数与“std::string *”类型的参数不兼容