Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: code efficiencies with pointers (http://www.velocityreviews.com/forums/t267640-re-code-efficiencies-with-pointers.html)

Victor Bazarov 06-24-2003 01:38 AM

Re: code efficiencies with pointers
 
"pw" <no_email_delete_@bigpond.net> wrote...
> My last questions on pointers:
>
> Is it fair to say that argument/object naming is really a convenience

(i.e.
> an aid) to use in place of pointers and references to help people

understand
> and write the code? [This leads to the next Q]


Well, yes, if instead of names we'd use addresses, we'd have, well,
machine code. High-level languages have this feature, odd as it may
be, named objects. In programmer lingo they are known as variables.

> Is it then correct to say that pointers and references are more efficient

in
> terms of machine performance, particularly in the case of larger objects.
> Instead of passing a whole object, you pass the pointer/reference to that
> object? This would then be a consideration on what is the size of the

object
> your are passing?


Yes, I believe that is correct. If you're passing an int, it's often
faster to pass by value than otherwise (if you don't need any change
to it to be visible outside). But for larger objects, passing by ref
or pointer can be faster. Especially if copying involves invoking some
kind of function (like a copy c-tor).

> Pointers and references would then be "essential" for larger code, with
> arguments OK for small basic code, or small basic objects? Thus, when
> defining functions, is it better to use reference passing instead of

object
> passing?


That depends. Pointers and references are _essential_ for polymorphism.
There is no polymorphism without them. Often that involves pure abstract
interfaces, which by themselves are very light and _could_ be passed by
value without any performance degradation. However, passing values in
such case would be disastrous. [ See "slicing" ]

> Therefore, the sooner I come to understand and use pointers and

references,
> the better the programs I would be creating.


That's true WRT any part of the language.

Victor




All times are GMT. The time now is 08:40 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.