patterngoCritical
Are maps passed by value or by reference in Go?
Viewed 0 times
arevaluepassedmapsreference
Problem
Are maps passed by value or reference in Go ?
It is always possible to define a function as following, but is this an overkill ?
Same question for return value. Should I return a pointer to the map, or return the map as value ?
The intention is of course to avoid unnecessary data copy.
It is always possible to define a function as following, but is this an overkill ?
func foo(dat *map[string]interface{}) {...}Same question for return value. Should I return a pointer to the map, or return the map as value ?
The intention is of course to avoid unnecessary data copy.
Solution
In this thread you will find your answer :
Golang: Accessing a map using its reference
You don't need to use a pointer with a map.
Map types are reference types, like pointers or slices[1]
If you needed to change the Session you could use a pointer:
https://blog.golang.org/go-maps-in-action
Golang: Accessing a map using its reference
You don't need to use a pointer with a map.
Map types are reference types, like pointers or slices[1]
If you needed to change the Session you could use a pointer:
map[string]*Sessionhttps://blog.golang.org/go-maps-in-action
Code Snippets
map[string]*SessionContext
Stack Overflow Q#40680981, score: 166
Revisions (0)
No revisions yet.