References are a lot safer than pointers because you don't have as many
problems with memory leaks, and a caller can call a reference function and a
non-reference function (perhaps you actually do want to copy an input
variable because your function corrupts the input deliberately) in the same
fashion. Therefore, in general, C++ programmers are strongly encouraged to
use references instead of pointers when possible.
Often, one finds that it's possible to design equally efficient methods of
dealing with your data that do not require pointers, which is a VERY good
thing. This is the beauty of container classes. If you pass them as a
reference or a constant reference, you can shuffle your data around quickly
just like with a pointer, but the ~container destuctor function makes it
essentially impossible to leak memory!
Just some thoughts,
Matthew Hall
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Per
Westermark
Sent: Thursday, May 05, 2005 5:28 PM
To: Jakob EKlund
Cc: dev...@li...
Subject: Re: [Dev-C++] Pointers references and speed
Internally, references and pointers are identical. The change is only in
syntax.
/Per W
On Thu, 5 May 2005, Jakob EKlund wrote:
> Is there any known differens in speed between pointers and references?
>
> //is there any accessspeed difference between
> int * pointer;
> //and
> int &reference;
>
> Or is there any other complication considering references that I should be
> aware about before starting to use them?
>
> /Jakob Eklund
-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
___________________________________________________________________
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
|