Skip to main content
GameDev.net gamedev.net
๐Ÿ”’ Locked

performance: const pointer vs reference

Started by qed Nov 26, 2000 at 2:38 PM 2 replies 200+ views
Original Post
qed
qed
I was wondering if there is a performance difference between using a const pointer or a reference as an argument of a function. Does anybody know? (i know there are aesthetic and other reasons to use references but my question concerns only potential performance differences) e.g.: do_something(myclass * const) or do_something(myclass &)
Wilka
Wilka
Nope, the compiler should produce the same code for both. But the reference is potentially faster, cos you can''t have a NULL reference so there''s no need to check before you start using it.
qed
qed
So if I don''t check for NULL it''s *exactly* as fast? (I know a reference can *potentially* be faster than a non-const pointer)
Stoffel
Stoffel
Yes.

You can (and should) always generate a source code listing to test any of these kinds of questions yourself.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.