On Fri, 20 Oct 2017 08:49:16 -0000 Jan Mercl <0xj...@gmail.com> wrote: Jan Mercl writes: > > On Fri, Oct 20, 2017 at 10:39 AM Ian Davis <m...@iandavis.com> wrote: > > > How does that affect the size of []T or []*T ? > > No one said it does. What size of T affects is appending/inserting/deleting > items to/from the slice. If one passes around a value of type []T, those > operations are probably performed on the value.
On the flip side, []*T will be less cache/TLB/GC friendly than []T, unless T is much larger than a ptr. You are also allocating an extra pointer per element. For small slices it probably doesn't matter much either way but when slices hold milions of objects.... Elements of []T are less likely to be mangled from random places compared to []*T as in the latter case you may have access through other ptrs. IO and comm will also be easier with []T. []*T makes sense where there is genuine need to share. e.g. put an object on multiple lists. Otherwise it can often just be premature optimization. -- 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.