On Thu, Nov 19, 2015 at 2:01 PM Larry wrote:
if you implement a mathematical library that uses pointers in its
function params, how does this affect performance? Is there a cost to the
Yes, there's always a cost of indirection (accessing a value through
dereferencing a pointer). There's also always a cost of copying a
non-indirected value. Which of the costs is greater depends on many things,
including a particular CPU architecture/model/cache sizes. Other than that,
a rough estimate is that copying a "small" value, for some value of small,
might have also a rather small cost, ie. using a pointer instead might not
be necessary. OTOH, passing "big" values by value (copying them) is
probably always something one should try to avoid.
Also, presumably not using pointers results in a new copy being added to
heap that needs to be GCd later. Is that the only difference from a memory
Copying a value up to certain (quite big) size is performed on the stack so
it does not create any GC pressure.
Finally, if there is a reference to performance, memory and GC that
covers all this, a pointer (no pun intended) would be appreciated.
I think the best, perhaps the only good option, is to benchmark (go test
-bench <re>) the numbers for yourself and for the particular machine and
program (add -benchmem to get also mem stats).
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 firstname.lastname@example.org.
For more options, visit https://groups.google.com/d/optout.