+ 2
Efficiency: Pointer vs. Reference
In a much earlier discussion there was a comparison between call by value and pointers. The gist, as far as I remember, was that for small arguments like an int, a char or something like that, pointers don't make a lot of sense just for efficiency because a pointer also has a certain size, and that the advantages only come in when the size of the arg surpasses the size of its pointer. How is this for references? How do they compare to pointers regarding memory cost and speed?
3 odpowiedzi
+ 4
Really doesn't matter. The compiler is able to generate the same code, and that without optimizations on.
Here, you can test for yourself:
https://godbolt.org/z/MoNkwM
Also, you might want to bookmark that site, it's the number 1 site to go to for these kind of questions.
+ 2
Functions with parameters use pointers. It cannot be avoided
+ 2
Okay, guys, nice to know - so a reference is a pointer that just can't stop pointing. :)
Thank you!