On Wednesday, November 13, 2019 at 3:22:56 PM UTC-5, Brian Candler wrote: > > > the current implementation of interfaces is that they always store > pointer > > values. If you store a non-pointer value in an interface, that value > > is copied into memory, and a pointer to that memory is stored in the > > interface. > > I don't understand where you say "that value is copied into memory". If > we're talking about a value that already exists, surely it just obtains a > pointer to it, without any copying? > I don't think it does, and that would not even be possible. If it did just use a pointer to the original value then modifications to the original would be reflected in the interface. If the interface holds a value, not a pointer, then that would be very unexpected. I think this code https://play.golang.org/p/9H4AFIGy-1I illustrates that a copy is indeed made when a interface holds a value.
-- 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/219fabe2-b555-48b5-b022-926ba131b91c%40googlegroups.com.