On Mon, May 1, 2017 at 6:03 AM, feilengcui008 <feilengcui...@gmail.com> wrote: > > I have made a little testing about interface assignment and searched the > source code about interface runtime functions like convI2I, and notice that > there are two situations where data may be copied or not: > (1) data not copied: assign another interface type variable to the > targeted interface variable > (2) data copied and memory allocated: assign another not interface type > variable to the targeted interface variable > > I wonder are there any special reasons for that? > Thanks in advance! following is my simple testing code and debug info
Interfaces hold values that must not change while they are in the interface. When assigning from one interface value to another, it's fine to simply copy the pointer, as we already know that the value can't change. When assigning in or out of an interface value, in general we need to copy the value so that any changes to the value (such as changing a field in a struct) do not affect the value in the interface. Ian -- 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. For more options, visit https://groups.google.com/d/optout.