This is the mail archive of the libstdc++@sources.redhat.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: ptr vs ref performance?


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]