Are there performance implications when using pointers?
Is it better to avoid using pointers and if so, under what circumstances? Obviously they help, along with references, to reduce data copying. I presume if the data type being pointed to is small, the need for a pointer is smaller. In contrast, it is better to pass a large object via pointer as the overhead of the pointer is smaller than the overhead of copying the object.
I was also wondering about pointers in areas other than arguments/parameters?
Are references generally better than pointers in this performance context?
I appreciated I am bordering on the SO “dirty” topic of micro-optimizations but I am writing a very latency-focussed app.
I know that performance can be important, but semantics are more important: fast and wrong is useless.
Using pointers or references have semantics implications, such as sharing:
In the case
a.b == 0, then the first field ofahas been changed but not its second.Also, such sharing may create potential aliasing:
In the first case, the two structures are necessarily distinct, but in the latter they are not. This possible aliasing might prevent optimizations.
Focus on semantics first. Once you get them right, you can tweak and measure the effects in your particular situation.