You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
为什么每次返回请求数据都要new分配内存呢?直接返回新建/查询到的数据不行吗?如:
func (a *App) NewInstance(ni *Instance, latestTime int64) (i *Instance, ok bool) {
i = new(Instance)
a.lock.Lock()
...
*i = *ni
...
}
func (a *App) Cancel(hostname string, latestTime int64) (i *Instance, l int, ok bool) {
i = new(Instance)
oi, ok := a.instances[hostname]
...
*i = *oi
}
且多处返回空数据也会使用new,如此会产生大量gc吧。如:
func (a *App) Renew(hostname string) (i *Instance, ok bool) {
i = new(Instance)
a.lock.Lock()
defer a.lock.Unlock()
oi, ok := a.instances[hostname]
if !ok {
return // i = new(Instance) 应放在此if之后吧?
}
oi.RenewTimestamp = time.Now().UnixNano()
i = copyInstance(oi)
return
}
The text was updated successfully, but these errors were encountered:
为什么每次返回请求数据都要new分配内存呢?直接返回新建/查询到的数据不行吗?如:
func (a *App) NewInstance(ni *Instance, latestTime int64) (i *Instance, ok bool) {
i = new(Instance)
a.lock.Lock()
...
*i = *ni
...
}
func (a *App) Cancel(hostname string, latestTime int64) (i *Instance, l int, ok bool) {
i = new(Instance)
oi, ok := a.instances[hostname]
...
*i = *oi
}
且多处返回空数据也会使用new,如此会产生大量gc吧。如:
func (a *App) Renew(hostname string) (i *Instance, ok bool) {
i = new(Instance)
a.lock.Lock()
defer a.lock.Unlock()
oi, ok := a.instances[hostname]
if !ok {
return // i = new(Instance) 应放在此if之后吧?
}
oi.RenewTimestamp = time.Now().UnixNano()
i = copyInstance(oi)
return
}
The text was updated successfully, but these errors were encountered: