I came to go from the C++ world and in C++ usually when you care about performance and you don't need you object to be changed, you pass it using constant reference
void func(const std::string& str)
In this case, the string is NOT COPIED and cannot be modified in the function.
I know, that in Go there are two ways to pass object:
So, what is best approach? Always pass object by pointer even if you don't want to modify it because it is faster? Or there are some compiler optimizations and even if you send it by value sometimes it is sent as reference?
There's no direct equivalent in Go.
Example:
func doMap(m *map[string]string) {
if *m == nil {
*m = map[string]string{}
}
.....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With