#When making methods on structs is it better for performance to not pass the struct as a pointer?

5 messages · Page 1 of 1 (latest)

green igloo
#

Most of the time you should just do what's natural imo.

If you're creating pointers just to return a pointer, or dereferencing a pointer just to pass by value you're asking for more bugs in your code.

#

Unless it is a very large struct I guess it doesn't matter, if it is, I guess I'd use a pointer.

#

Also maps are reference types, which means that when you pass a map to a function or assign it to a variable, you are actually passing a reference to the original map.

rough gyro
#

If you want to know when it's better to pass pointers vs vals, look up the go ABI for your particular architecture.

rough gyro
#

this probably isn't a good benchmark. you should use the built-in benchmarking tools to figure out stuff like this.