User Tools

Site Tools


variable_models_in_go

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
variable_models_in_go [2018/01/18 15:22]
luciano [Variable models in Go]
variable_models_in_go [2018/02/24 12:23] (current)
luciano [References]
Line 12: Line 12:
 Yes. But what are the values? Yes. But what are the values?
  
-If you have an array with 1 million elements and you pass that array to a function directly (without using a pointer), the entire array with 1 million elements will be copied to the parameter variable, which is a local variable in the function.+If you have an array with 1 million elements and you pass that array to a function directly (without using a pointer), the entire array with 1 million elements will be copied to the parameter variable, which is a local variable in the function. A variable of any array type holds all the elements of the array, just like a simple '​int'​ variable holds the bits of the integer
  
 However, if you pass a slice to a function, the elements are not copied. The value of a slice is a hidden struct describing it. That struct has three fields: However, if you pass a slice to a function, the elements are not copied. The value of a slice is a hidden struct describing it. That struct has three fields:
Line 34: Line 34:
 ===== References ===== ===== References =====
  
 +  * [[https://​golang.org/​doc/​faq#​references|Why are maps, slices, and channels references while arrays are values?]] in the official Go FAQ
   * [[https://​blog.golang.org/​go-slices-usage-and-internals|Go Slices: usage and internals]]:​ by Andrew Gerrand in the official Go Blog.    * [[https://​blog.golang.org/​go-slices-usage-and-internals|Go Slices: usage and internals]]:​ by Andrew Gerrand in the official Go Blog. 
   * [[https://​www.goinggo.net/​2013/​08/​understanding-slices-in-go-programming.html|Understanding slices]]: by Bill Kennedy, showing ''​unsafe''​ inspection of slice values.   * [[https://​www.goinggo.net/​2013/​08/​understanding-slices-in-go-programming.html|Understanding slices]]: by Bill Kennedy, showing ''​unsafe''​ inspection of slice values.
   * [[https://​www.calhoun.io/​why-are-slices-sometimes-altered-when-passed-by-value-in-go/​|Why are slices sometimes altered when passed by value in Go?]] by John Calhoun.   * [[https://​www.calhoun.io/​why-are-slices-sometimes-altered-when-passed-by-value-in-go/​|Why are slices sometimes altered when passed by value in Go?]] by John Calhoun.
 +  * [[https://​nathanleclaire.com/​blog/​2014/​08/​09/​dont-get-bitten-by-pointer-vs-non-pointer-method-receivers-in-golang/​|Don'​t Get Bitten by Pointer vs Non-Pointer Method Receivers in Golang]]
 +
  
 ===== Ping back ===== ===== Ping back =====
  
-> If you liked this page or have comments, ​talk to me on Twitter: [[https://​twitter.com/​standupdev|@StandUpDev]]+> If you like what you just read, please share it! 
 +> For comments ​or suggestionsplease ping me on Twitter: [[https://​twitter.com/​standupdev/|@standupdev]]
  
-{{tag>​golang programming_language}}+{{tag>​golang programming_language ​reference_variables}}
  
 ~~DISQUS~~ ~~DISQUS~~
variable_models_in_go.1516317755.txt.gz · Last modified: 2018/01/18 15:22 by luciano