go语言中空结构体的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/MBuger/article/details/79758831

简介
go语言中的struct是一种很重要的语法,里面可以存放各种字段,当然它里面也可以为空。这样可以用来单纯的做控制信息。
示例

type Cli struct {
    Request *http.Request
    ReqBody []byte
    N int
    C int
    QPS float64
    M string
    Req *http.Request

    Writer io.Writer
    start time.Time
    stopChan chan struct{}//设计一个空的结构体用来做通道消息
    result chan *result
    report *report
}

这因为struct空的大小为0,所以这样可以在一定程度上减少内存使用,特别是在消息管道开辟数量到达一定量级之后。

猜你喜欢

转载自blog.csdn.net/MBuger/article/details/79758831