You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The "address" of a map reflect.Value is actually the address of the struct field so although maps are reference types they get treated as if they have been copied if two e.g. structs reference the same map.
Not sure we can actually solve this
package main
import (
"fmt""reflect"
)
typecontainerstruct {
linksmap[string]string
}
funcmain() {
test:=&container{
map[string]string{"hello":"world"},
}
copied:=&container{}
copied.links=test.links// here UnsafeAddr() (which we use for unique ids) are differentfmt.Println(reflect.ValueOf(test).Elem().Field(0).UnsafeAddr(), reflect.ValueOf(copied).Elem().Field(0).UnsafeAddr())
}
The text was updated successfully, but these errors were encountered:
The "address" of a map reflect.Value is actually the address of the struct field so although maps are reference types they get treated as if they have been copied if two e.g. structs reference the same map.
Not sure we can actually solve this
The text was updated successfully, but these errors were encountered: