AB said:
Hello All
Suppose I've got two functions declared thus..
void func(const Type& val) ;
and
void func(const Type* val) ;
In terms of ease (read speed) in data retrieval which method is more
expensive(if at all so)?
You will have to measure yourself. However, the best guess to make without
measuring is that there will be no difference in performance whatsoever:
your compiler might implement references as pointers anyway. However,
references make some guarantees that pointers do not make whence the
compiler might be able to optimize the reference version better. Then
again, such optimizations might be buggy in your compiler and yield actual
pessimizations. So you will just have to measure. It could depend on
compiler, context, function body, ...
Also, you should first base your decision of whether to use pass-by-pointer
or pass-by-reference not on performance but on code-readability: which
version does communicate intent?
Best
Kai-Uwe Bux