On Tue, Mar 6, 2018 at 1:23 PM, <[email protected]> wrote:
> go version 1.10
>
>
> Operating system and processor architecture
>
> GOHOSTARCH="amd64"
> GOHOSTOS="darwin"
> However, this happens in play.golang.org env as well.
>
>
> Checkout the code.
>
> https://play.golang.org/p/v6u7R_nbGRp
doc1 := Document{}
// Here, doc1.Data is nil
ds := DataStore{Doc: doc1}
// Here, ds.Doc has a copy of doc1, and ds.Doc.Data is nil
ds.Doc.Data = DocData{}
// Here, ds.Doc.Data is initialized, but not doc1.Data, because
ds.Doc is a copy of doc1
On the other hand:
doc2 := Document{Data: DocData{}}
// Here, doc2.Data is initialized to an empty map
ds2 := DataStore{Doc: doc2}
// And here, ds2.Doc is a copy of doc2, which contains a reference to
that empty map. The underlying maps are shared.
>
>
> In the example, if the struct (Document) is not initialized at first, there
> is no place holder for future values pointing to same object. Is this
> intended?
>
> --
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.