If your goal is to create an empty map that can store the same number of keys as the map used in the previous iteration, pass the desired size for the new map as the second parameter to make. That will reduce or eliminate the number of times the map is resized each round.
But if you have relatively few key collisions each round, it might be more efficient to append your items to a slice then sort them at the end to identify duplicates. Then just reslice down to zero at the start of each round to reuse the underlying array.
Profile your code and see.
There's no simple and easy way to clear a map that I'm aware of. It is normally just easier to create a new one. Alternatively, are you able to solve your problem using arrays/slices?
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Perhaps use a sync.Pool to recycle maps in your server.
--
make() a new one is faster than emptying the old one. Both result in the same amount of garbage, but the former does less paperwork beforehand.
I had assumed that the OP was talking about a map with indirect keys/values, in that case I believe those keys/values will become garbage after deletion. At least in 1.4 when there is no more free method inside the runtime.