Is pass by value less efficient? It's more on the stack so it must be compared to pass by refrence like c, c++. anyone have thoughts on this?
Pass by value
Page 1 of 15 Replies - 855 Views - Last Post: 07 January 2009 - 04:54 AM
Replies To: Pass by value
#2
Re: Pass by value
Posted 06 January 2009 - 07:41 PM
Pass by value creates a copy. (slow, Depends on size of object)
Pass by reference creates a pointer to the value. (Fast,Typically 4 bytes in size)
Pass by reference creates a pointer to the value. (Fast,Typically 4 bytes in size)
#3
Re: Pass by value
Posted 06 January 2009 - 07:45 PM
It depends if you're asking about efficiency in regards to memory consumption or speed. Generally passing by reference is faster/more efficient in both instances.
edited for a typo
edited for a typo
This post has been edited by KYA: 06 January 2009 - 07:46 PM
#4
Re: Pass by value
Posted 06 January 2009 - 08:12 PM
Yea knew what they were LOL. So are you saying that pass by value consumes less ram though? I never thought of the 2 efficiency sides of it. I thought ram was speed and how much memory needed to be readily availible. Never thought of it like that though.
#5
Re: Pass by value
Posted 06 January 2009 - 09:06 PM
Since you have to create a shallow copy you are using more memory when passing by value. Passing by references uses less physical memory.
#6
Re: Pass by value
Posted 07 January 2009 - 04:54 AM
The only time to pass by value is if that value is a small primitive. Or you actually want to work on a copy and no the original.
For example, references are usually of int size, so to only reason to pass an int by ref is to modify it. Also, most examples of recursion you see will make use of pass by value for math problems.
Yes, a copy must be made for pass by value, and if the thing you're copying is big you're taking a big hit.
For example, references are usually of int size, so to only reason to pass an int by ref is to modify it. Also, most examples of recursion you see will make use of pass by value for math problems.
Yes, a copy must be made for pass by value, and if the thing you're copying is big you're taking a big hit.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote





|