Good evening, I’m learning Go and I have a question (I think it’s pretty basic)
I created a map as follows.
m1 = make(map[string]someStruct)
m1["a"] = struct1
m1["b"] = struct2
I have another map with which I am going to reference the objects in the previous map.
Is better to have a map of strings (which are the keys of the primary map) or a map of pointers to struct?
m2 = make(map[string]string)
m2["1"] = "a"
m2["2"] = "b"
m2 = make(map[string]*someStruct)
m2["1"] = &struct1
m2["2"] = &struct2
In the second case, I can directly access the final value without having to perform an additional search on the primary map (map searches are O(1), so it should not be too onerous).
I would like to know from the point of view of memory which is the best option (there are many values to put in the map, so optimizing memory is quite important.
Thank you in advance