On Friday, 11 August 2023 at 17:56:01 UTC+1 Shinya Sakae wrote:

I often hear the term `shallow copy', but I don't know what `shallow clone` 
means.


Don't worry: they are the same thing.

When cloning a map, the keys and values are set using ordinary assignment, 
as the description says.  It means there is no recursive cloning of nested 
structures.

For example: assignment of a map ends up with two values pointing at the 
*same* data structure:
https://go.dev/play/p/NzCII0hy92R
(that's why clone is needed in the first place: so you can 
add/update/delete to the clone, without affecting the source map)

Therefore, if you have an outer map containing inner maps as values, and 
you clone the outer map, the clone will still refer to the same inner maps.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/27dac806-a1a8-42bd-bbe1-06d21a796eedn%40googlegroups.com.

Reply via email to