Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: code efficiencies with pointers

Reply
Thread Tools

Re: code efficiencies with pointers

 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-24-2003
"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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
regx, global efficiencies? oldyork90 Javascript 4 06-10-2008 11:43 AM
c++: pointers to pointers A C++ 3 10-29-2003 01:15 PM
pointers to pointers // exception handling error muser C++ 3 09-18-2003 06:19 PM
Template specialization of pointers with function pointers Phil C++ 1 09-16-2003 02:17 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57