指针来共享结构体而不是拷贝本身似乎是性能方面的最佳选择。
今天看到项目里有的结构体用指针来共享,有的不用,然后上网查了下资料,发现:
指针来共享结构体而不是拷贝本身似乎是性能方面的最佳选择
再看了下项目,发现:
type RemindArg struct {
Content string `json:"content"`
}
func RemindNew(c *Context) {
arg := RemindArg{}
}
type Context struct {
W http.ResponseWriter
R *http.Request
PS httprouter.Params
CTime time.Time
goNext bool
UUID string
keys map[string]interface{}
rawData []byte
}
像Context
这种上下文的路由(也就是拿来接收或反馈数据给前端的一个容器),写crud的时候经常用到,所以此结构体可以用指针来共享
像RemindArg
这种就一两个地方用到了的,还是拷贝结构体共享吧