Passing a ByRef parameter 
Author Message
 Passing a ByRef parameter

Hi all..

I have read that passing a parameter ByRef  is more inefficient than passing
it ByVal. Why is this? I supposed that passing ByRef, a pointer to the
actual parameter is passed, but maybe not.

Can you explain me this point?

Thanks
Jaime



Sun, 12 Sep 2004 22:39:56 GMT  
 Passing a ByRef parameter
I'd like this explained to me too. I've read in a number of places this is
the case, but I don't understand it.

I can see how it would help maybe if passing between two COM+ components on
different machines, in that one machine can't have a pointer to another's
memory space, but I fail to see how passing how passing a recordset, for
example, using ByVal and thus making a copy of the entire recordset is more
efficient than passing a 4-byte pointer.

Anyone?


Quote:
> Hi all..

> I have read that passing a parameter ByRef  is more inefficient than
passing
> it ByVal. Why is this? I supposed that passing ByRef, a pointer to the
> actual parameter is passed, but maybe not.

> Can you explain me this point?

> Thanks
> Jaime



Sun, 12 Sep 2004 22:49:02 GMT  
 Passing a ByRef parameter


Quote:
> I'd like this explained to me too. I've read in a number of places this is
> the case, but I don't understand it.

> I can see how it would help maybe if passing between two COM+ components
on
> different machines, in that one machine can't have a pointer to another's
> memory space, but I fail to see how passing how passing a recordset, for
> example, using ByVal and thus making a copy of the entire recordset is
more
> efficient than passing a 4-byte pointer.



go out to http://groups.google.com/groups and search for "byval vs byref"
and you'll find many discussions.

Neither is "best" since it depends on a number of factors.  In-process using
"byref:" is generally more efficient since the called routine can just
access the original data directly.  Out-of-process the data has to be copied
from the caller to the callee and if it is 'byref' it has to be copied back
so using 'byval' can avoid that second copy.  With objects you have to
remember that you are *not* passing the entire object, you are passing the
reference to the object so chances are that you aren't making a copy of that
entire recordset.

IMO, except where you are passing very large amounts of data and/or calling
the procedure many many times it is more important to use ByVal or ByRef to
indicate whether the value will be changed by the caller or not.  In most
cases any perfromance difference is minimal while the gain in code
readability can be significant.



Sun, 12 Sep 2004 23:05:24 GMT  
 Passing a ByRef parameter
Try article Q161308 on Microsoft's knowledge base.


Quote:
> I'd like this explained to me too. I've read in a number of places this is
> the case, but I don't understand it.

> I can see how it would help maybe if passing between two COM+ components
on
> different machines, in that one machine can't have a pointer to another's
> memory space, but I fail to see how passing how passing a recordset, for
> example, using ByVal and thus making a copy of the entire recordset is
more
> efficient than passing a 4-byte pointer.

> Anyone?



> > Hi all..

> > I have read that passing a parameter ByRef  is more inefficient than
> passing
> > it ByVal. Why is this? I supposed that passing ByRef, a pointer to the
> > actual parameter is passed, but maybe not.

> > Can you explain me this point?

> > Thanks
> > Jaime



Mon, 13 Sep 2004 01:41:14 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. > passing vb6 optional byref parameter into c#

2. Passing Parameters - A ByRef vs ByVal Question

3. Help, OA ByRef parameters not passed correctly

4. passing ByRef parameters

5. Passing Byref parameter to an ocx method

6. Passing parameters ByRef or ByVal

7. call com object with byref byte parameters in vb.net

8. call com object with byref byte parameters in vb.net

9. ByRef parameter, simple questions..

10. Creating constructors with byref parameters

11. ByRef Parameters in Subs

12. byref boolean parameter problems

 

 
Powered by phpBB® Forum Software