On Sat, Jun 5, 2021 at 2:15 PM Joshua <joshua.oconno...@gmail.com> wrote: > > My question is general, but for ease of communicating I'll use the specific > example I ran into. > > I'm very new and for my first project I'm working with the bleve library > [https://pkg.go.dev/github.com/blevesearch/bleve]. > > One function I need, "Open", returns an interface, "Index". > > I'd like to write my own function to act on this interface, and given that I > have no idea what the dynamic value of the interface is, my first instinct is > to rather pass a pointer to the returned interface into my function. > > However, I see lots of calls of "If you're using pointers to interfaces a > lot, you probably don't understand them". > > Well, what am I not understanding? > My worry is that I have no idea what dynamic type is lurking within the > interface, if it's a pointer to a struct, then I obviously don't mind passing > it into my function. > > However if it is in fact a humungous 1GB struct, then I really really don't > want to be copying that around willy-nilly. > > Is there a way in general to avoid this, without looking at the library > source code to see what the actual concrete type is?
In the current implementations a value of interface type is always a pair of pointers. Even if the value of interface type happens to refer to a 1GB struct, copying the interface value, including passing it to a function or returning it from a function, always just copies two pointers. 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUuv_qrrG8%3DdCQZv0%2BrKbnbW60XdOCwjp8M3EdOCxCNkw%40mail.gmail.com.