C++ pointers and optimization -
i have read c++ compiler optimization (,or @ least should) , programmer shouldn't worry too much it.
but how compare pointers? seems every time make function have decide whether use pointers or not. what's reason behind this? shouldn't compiler far possible?
and isn't there keyword can use in method signature states objects given parameter won't mutated compiler optimize stuff?
and why is(n't) there one?
using object argument, compiler may or may not copy ellision depending on many factors. if in doubt compiler can make safe assumption function may want change argument , may avoid copy elision optimization.
instead if use (const) reference or pointer, provides stronger guarantee compiler either object won't change or changes done locally in function required in caller also.
in general 1 should avoid avoid micro optimizations unless proven bottleneck using profiling , concentrate on readability of code better maintenance , architectural changes can give higher optimization , can not suggested/performed tools.
Comments
Post a Comment