Re: code efficiencies with pointers
"pw" <email@example.com> wrote...
> My last questions on pointers:
> Is it fair to say that argument/object naming is really a convenience
> an aid) to use in place of pointers and references to help people
> 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
> 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
> 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
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
> the better the programs I would be creating.
That's true WRT any part of the language.
|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.