You have a large struct in your Go program that you need to pass to a function for processing. Which method of passing the struct would be more efficient: passing by value or passing by pointer?

  • Both methods are equally efficient
  • It depends on the size of the struct
  • Passing by pointer
  • Passing by value
Passing by pointer would be more efficient because it avoids copying the entire struct's data, which can be costly for large structs. When you pass a struct by value, a copy of the entire struct is made, which can consume significant memory and time, especially for large structs. Passing by pointer allows passing a reference to the struct, avoiding this overhead.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *