Why use make with maps?

in this code snippet, why do you have to use make to create a new empty map? why not just do the same but without make?

    // keys of map are strings, values are int
    // make creates a new empty map
    counts := make(map[string]int)

You need it to generate the fat pointer that points at the actual map, also it pre-allocates some memory for the future content of the map.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.