H
hasho
Why is "call by address" faster than "call by value"?
hasho said:Why is "call by address" faster than "call by value"?
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.
lallous said:*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.
Joona said: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?
>
> Call by address does at least one copy. The address needs to be copied
> last time I checked.
>
>
> The speed issue comes from the fact that with an address less might
> need to be copied. Consider passing structures for example.
http://www.cwi.nl/~dik/Dik T. Winter said: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.
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?
> news:[email protected]... ....
>
> 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.
hasho said:Why is "call by address" faster than "call by value"?
Dik said: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.
Leor Zolman said:It is not clear to me that C "defines" call by /anything/, as the only
place I could locate the term "call by value" in the Standard was in
the index, referring to section 6.5.2.2, but the term itself doesn't
even seem to be used in that section.
Colloquially, I usually use the terms "pass by value" and "pass by
name" (or reference, or pointer...although using "reference" can be
problematic in C++) /in close conjunction/ with the object being
passed that way. For example:
int i, j;
foo(i); // pass i by value
bar(&i); // pass i by reference
Dik T. Winter said: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.
I think Dik's point is that with call by address, you have to jump to that
address to get the data. If that data happened to be out of segment, or in
paged memory, you could get a bad performance hit.
The other point is that most architectures have registers. Passing values
in registers is generally way faster than using pointers.
Whereas when calling by value, a copy of the structure will be made before.
Which is a one-time hit.
So the real answer is "it depends, go test it in your situation".
For what its worth, I've found situations where pass by value, even of huge
structures, was way more performant. No idea why, but OpenVMS on AXP
hardware seemed to perfer that.
hasho said:Why is "call by address" faster than "call by value"?
This may be true for structures.hasho said:Why is "call by address" faster than "call by value"?
Why is "call by address" faster than "call by value"?
Call by address does at least one copy. The address needs to be copied
last time I checked.
(snip)
The speed issue comes from the fact that with an address less might
need to be copied. Consider passing structures for example.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.