This is the mail archive of the
libstdc++@sources.redhat.com
mailing list for the libstdc++ project.
Re: ptr vs ref performance?
- To: libstdc++ at sources dot redhat dot com
- Subject: Re: ptr vs ref performance?
- From: Nathan Myers <ncm at nospam dot cantrip dot org>
- Date: Thu, 14 Dec 2000 19:10:00 -0800
- References: <3A3967DC.9AC77A53@e-critical.com>
- Reply-To: libstdc++ at sources dot redhat dot com
On Thu, Dec 14, 2000 at 04:37:48PM -0800, Rob Willis wrote:
> In the process of playing with the performance of "long long" types, i
> noticed another oddity. It appears as if using a reference variable is
> faster than de-referencing from a pointer. My assumption would of been
> that the time for these operations would be exactly the same, but
> obviously there is something more going on in ptr dereferences...
When memory gets written to, the compiler must often assume that any
pointers that live there might have been clobbered, and have to be
reloaded. For references, the compiler can optimize based on an
invariant: references cannot legally be changed. Therefore, the
compiler can assume that its in-register copy of the reference is
the same as the definitive memory version, even though some memory
has been written to.
Nathan Myers
ncm at cantrip dot org