Golang is a native programming language. So there is a lot of limitation than dynamic languages (like python and ruby).
When initialize Maps as m := make(Map[string]int)
, this map m
seems to be able to contain infinity many key-values.
But when initialize Maps with maps literal or make with cap, The maps cannot contain infinity many key-values.
Some article said that make without cap allocate a huge amount of memory to this map. But this is not option, because if it was true, there will be a giant memory consumption when initialize single map. But no matter what computer hardware monitoring tools I use, the memory is no difference between before and during my program runs.
func main(){
Hello()
}
func Hello(){
m := make(SizeRecord)
l := 10000000
for i := 0; i < l; i++ {
m[strconv.Itoa(i)] = Size{float64(rand.Intn(100)), float64(rand.Intn(100)), float64(rand.Intn(100))}
}
fmt.Println(m)
}
The program take a while to be executed.
I also read an article Go maps in action, it said (I don't know if I have understood correctly) that make without cap use an alternative implementation to represent map and use an unified interface to access the map as the other maps with limited capacity.
If my understanding is wrong, could any body tell me what correct one is?
If I am correct, why didn't golang implement all maps in this way?