Hi Brian.
Thanks for reaching out.
I understand.

On Monday, August 14, 2023 at 4:11:56 PM UTC+9 Brian Candler wrote:

> 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/3c8d4d61-5d81-4dd8-b042-d4333ae920d0n%40googlegroups.com.

Reply via email to