I have a collection of objects that will sometime have new element added to it.
How do I increase the internal map size?
Do I need to reallocate the whole map every time the element count exceed allocated count?
The Go specification says:
A new, empty map value is made using the built-in function make, which takes the map type and an optional capacity hint as arguments:
make(map[string]int) make(map[string]int, 100)
The initial capacity does not bound its size: maps grow to accommodate the number of items stored in them
So, no, you don't have to make any allocations to a map once you've created it. This is handled internally by the Go runtime. The optional capacity used when making the map it's only a hint, not a limitation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With