We are aware that using pointers for passing parameters can avoid data copy, which will benefit the performance. Nevertheless, there are always some edge cases we might need concern. Let’s take this as an example: 1 2 3 4 5 6 7 8 9 10 11 12 13 // vec.go type vec struct { x, y, z, w float64 } …
我们都知道,使用指针传参可以避免数据拷贝,从而提升性能。然而,凡事总有例外。 来看这个例子: 1 2 3 4 5 6 7 8 9 10 11 12 13 // vec.go type vec struct { x, y, z, w float64 } func (v vec) addv(u vec) vec { return vec{v.x + u.x, v.y + u.y, v.z + …