Skip to content
This repository has been archived by the owner on Oct 21, 2019. It is now read-only.

Go 中函数间传递数组的注意事项 #41

Open
zwwhdls opened this issue Jul 30, 2019 · 0 comments
Open

Go 中函数间传递数组的注意事项 #41

zwwhdls opened this issue Jul 30, 2019 · 0 comments
Labels
tip 学习至少一个技术技巧

Comments

@zwwhdls
Copy link

zwwhdls commented Jul 30, 2019

Go 中函数间传递数组,尽量避免用数组,用指针和切片更好。
原因:函数间传递参数传递的是值,直接传递数组会增大不必要的内存;用指针传递的话只会开辟一个指针的内存,而切片也是只占用头指针的内存。
如下:

func test(a [12]int){} // 避免
func test(a []int){}
func test(a *[12]int){}
@zwwhdls zwwhdls added the tip 学习至少一个技术技巧 label Jul 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tip 学习至少一个技术技巧
Projects
None yet
Development

No branches or pull requests

1 participant