-3

I am new in Go world, the question could be obvious.

Let's say I have a struct Example, which has some methods:

type Example struct {}

func (e *Example) M1() {
  //do smth
}

func (e *Example) M2() {
  //do smth
}

func (e *Example) M3() {
  //do smth
}

I'm declaring a variable of type Example and want to pass it to another function.

func F1(example Example) {
  //do smth
}

How to determine whether I should pass the variable to another function by reference or by value? How are functions and methods located in memory?

Could you please share some articles or best practices?

Thanks a lot!

Lost_
  • 3
  • 3
  • 1. Nothing ever is passed by reference in Go. Passing a pointer value is done by value and is not "pass by reference". 2. Where (if at all) functions and methods are located in memory is an implementation detail. This changes, you do not need to know and the information is of no real use. 3. Looking for 3rd party documents etc. is OT. You will find all information you need on go.dev. – Volker May 06 '22 at 10:39

0 Answers0