0

go 我就不用指针不行?

 2 years ago
source link: https://www.v2ex.com/t/842797
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Go 编程语言

go 我就不用指针不行?

  frank1256 · 23 小时 53 分钟前 · 3287 次点击

搜索引擎告诉我的都是,要改变属性的话就要传指针。是因为如果用值传递,会进行复制一份。这我能理解。

如果不需要改属性就使用值传递,但是不也是复制了一份吗???只不过我没修改属性罢了。

那综上改属性和不改属性都会复制。那什么时候应该用值传递?值传递的所谓的复制一份,危害性很大?那为什么 go 要设计出值传递?

还有人说无脑用指针就行?平时的 crud 里,除了查询出结果的时候,做的赋值动作。需要指针,其他函数之间的流转基本都不会去修改属性的。我用值传递不行吗。

求大佬解答


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK