Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > call by address vs. call by value

Reply
Thread Tools

call by address vs. call by value

 
 
hasho
Guest
Posts: n/a
 
      02-10-2004
Why is "call by address" faster than "call by value"?
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      02-10-2004
hasho <(E-Mail Removed)> scribbled the following:
> Why is "call by address" faster than "call by value"?


It's not necessarily. It could be, but then it could be not. The C
standard does not define anything about what is faster than what. It is
strictly a QoI issue only.

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Bad things only happen to scoundrels."
- Moominmamma
 
Reply With Quote
 
 
 
 
lallous
Guest
Posts: n/a
 
      02-10-2004
*Ideally* call by address is faster because call by value makes a new copy
of the argument everytime you call the function.
Call by address does no copies instead pass the address of the variable as
is.

So basically the speed issue comes from the overhead produced by making
copies of the variables.

--
Elias
"hasho" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Why is "call by address" faster than "call by value"?



 
Reply With Quote
 
Erik
Guest
Posts: n/a
 
      02-10-2004
On 10 Feb 2004 04:35:52 -0800, the right honourable
http://www.velocityreviews.com/forums/(E-Mail Removed) (hasho) wrote:

>Why is "call by address" faster than "call by value"?


think of calling a hughe data structure by value...

And, btw. the two methods are not interchangeable without penalty, as
may be suggested by your question. they are completely different in
nature.

frgr
Erik

 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      02-10-2004
"lallous" <(E-Mail Removed)> wrote:

[ Don't top-post, please. ]

> "hasho" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > Why is "call by address" faster than "call by value"?

> *Ideally* call by address is faster because call by value makes a new copy
> of the argument everytime you call the function.
> Call by address does no copies instead pass the address of the variable as
> is.


That is the theory, based on a very restricted view of a rather
old-fashioned kind of implementation, with no arguments passed in
registers and rather larger objects than pointers. Actual practice
doesn't always agree with this theory.
In fact, in practice, which objects will be faster passed as pointers
and which are faster passed directly depends entirely on the
architecture, the compiler, and possibly even on the generation of the
architecture (i.e., it could differ between a Pentium II and a Pentium
III). The only way to know which is best for you is to measure, and not
to assume that your measurements are correct for others.
Even then, in most cases the difference between pointer and value
passing is likely to be dwarfed by algorithmic choices. If passing a
pointer makes calling the function slightly faster, but actually doing
anything inside the function slower, more complicated, and more error-
prone, only a fool uses the pointer. Ditto vice versa.

Richard
 
Reply With Quote
 
Thomas Stegen CES2000
Guest
Posts: n/a
 
      02-10-2004
lallous wrote:
> *Ideally* call by address is faster because call by value makes a new copy
> of the argument everytime you call the function.
> Call by address does no copies instead pass the address of the variable as
> is.


Call by address does at least one copy. The address needs to be copied
last time I checked.

>
> So basically the speed issue comes from the overhead produced by making
> copies of the variables.
>


The speed issue comes from the fact that with an address less might
need to be copied. Consider passing structures for example.

--
Thomas.

 
Reply With Quote
 
Grumble
Guest
Posts: n/a
 
      02-10-2004
Joona I Palaste wrote:

> hasho wrote:
>
>> Why is "call by address" faster than "call by value"?

>
> It's not necessarily. It could be, but then it could be not. The C
> standard does not define anything about what is faster than what.
> It is strictly a QoI issue only.


I thought that C defined only call by value, and that call by address
was merely mimicked by passing the value of a pointer to an object.

Perhaps I misunderstood?

 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      02-10-2004
Grumble <(E-Mail Removed)> scribbled the following:
> Joona I Palaste wrote:
>> hasho wrote:
>>> Why is "call by address" faster than "call by value"?

>> It's not necessarily. It could be, but then it could be not. The C
>> standard does not define anything about what is faster than what.
>> It is strictly a QoI issue only.


> I thought that C defined only call by value, and that call by address
> was merely mimicked by passing the value of a pointer to an object.


> Perhaps I misunderstood?


Well, technically you are right. I understood hasho's "call by address"
to mean "passing address with call by value".

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I wish someone we knew would die so we could leave them flowers."
- A 6-year-old girl, upon seeing flowers in a cemetery
 
Reply With Quote
 
Dik T. Winter
Guest
Posts: n/a
 
      02-10-2004
In article <4028e5bb$(E-Mail Removed)> Thomas Stegen CES2000 <(E-Mail Removed)> writes:
> lallous wrote:
> > *Ideally* call by address is faster because call by value makes a new copy
> > of the argument everytime you call the function.
> > Call by address does no copies instead pass the address of the variable as
> > is.

>
> Call by address does at least one copy. The address needs to be copied
> last time I checked.
>
> >
> > So basically the speed issue comes from the overhead produced by making
> > copies of the variables.
> >

>
> The speed issue comes from the fact that with an address less might
> need to be copied. Consider passing structures for example.


On the other hand call by address might mean that more has to be copied.
Consider passing structures by address for example, and you use each
field many times.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
 
Reply With Quote
 
lallous
Guest
Posts: n/a
 
      02-10-2004
"Dik T. Winter" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <4028e5bb$(E-Mail Removed)> Thomas Stegen CES2000

<(E-Mail Removed)> writes:
> > lallous wrote:
> > > *Ideally* call by address is faster because call by value makes a new

copy
> > > of the argument everytime you call the function.
> > > Call by address does no copies instead pass the address of the

variable as
> > > is.

> >
> > Call by address does at least one copy. The address needs to be copied
> > last time I checked.
> >
> > >
> > > So basically the speed issue comes from the overhead produced by

making
> > > copies of the variables.
> > >

> >
> > The speed issue comes from the fact that with an address less might
> > need to be copied. Consider passing structures for example.

>
> On the other hand call by address might mean that more has to be copied.
> Consider passing structures by address for example, and you use each
> field many times.
> --
> dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland,

+31205924131
> home: bovenover 215, 1025 jn amsterdam, nederland;

http://www.cwi.nl/~dik/

Hello

Dik and Thomas, I didn't understand your point?

When calling by address the only thing that is being copied is the address
of the variable that you're accessing by address.
That applies to structures or any other variable.

Whereas when calling by value, a copy of the structure will be made before.

--
Elias


 
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
HELP - Spreadsheet::ParseExce - Can't call method "value" on anundefined value perl Newbie Perl Misc 5 05-06-2009 09:44 AM
Help using Spreadsheet::ParseExcel Module - Can't call method "value"on an undefined value perl Newbie Perl Misc 2 05-06-2009 09:43 AM
Call by value vs. Call by reference Saeed Amrollahi C++ 10 07-15-2008 09:05 PM
Mocha raise exception first call, return value second call Raymond O'Connor Ruby 1 03-08-2007 08:38 AM
Routing to public IP of NAT address from internal NAT address Andrew Albert Cisco 1 02-08-2005 07:05 PM



Advertisments