首页 > 解决方案 > 为什么 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或其他类型?

在此处输入图像描述

标签: go

解决方案


为什么 Golang hchan struct 封闭字段使用 uint32 类型 [而不是 uint8]?

问你自己:

  • 使用 uint8 会得到什么?(提示:无)
  • 使用 uint8 会使代码更复杂吗?(提示:是的)

有时没有“深层”原因。uint32 运行良好并且很好。


推荐阅读