On Sun, May 26, 2013 at 1:05 PM, Nguyên Nguyễn Văn Cao wrote:
func GetAllItem() ([]Item, error)
func GetAllItem() ([]Item, error)
func GetAllItem() ([]*Item, error)
what an Item is, and how the data is expected to be moved/copied in
the algorithms that use it. With []Item, all the data is contiguous in
a single block, which is a significant advantage. But then, it means
that when you append an item to the slice, you're really appending a
copy of it, which isn't always okay. Also, if you do a lot of item
shuffling within that slice or other operations that force copying the
whole item rather than a pointer, it might compromise that initial
advantage.
In the end, as most things doing the best requires context. So, as a
rule of thumb, until you know best I suggest using []*Item whenever
you do need to preserve the original value instead of having a copy of
it, and []Item otherwise. Then, observe and profile to understand what
is going on.
The Go GC is great, so we can go around and throw garbage everywhere?
That's an easy one: no! :-)gustavo @ http://niemeyer.net
--
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/groups/opt_out.