Understanding the Difference Between map Initialization with and without make
When dealing with maps in Go, you may encounter two distinct forms of initialization:
1.使用映射文字: int {}
2。使用Make函数:var m = map[string]int{}string {false:“ false”,true:“ true”}
m:= mak = mak [t] u)在创建空映射时两种方法的行为相同。 m:= make(map [t] u,50)
它以50个元素分配的空格来初始化地图。如果预期地图增长,则预分配可以减少未来的内存分配。免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3