Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...If there has ever been a justification needed for access to the net during working hours, just referring to this site should suffice. Fantastic!..."

Geography

Where in the world do Tek-Tips members come from?

Effect of passing arguments ByVal and ByRef on Performance

jashy (Programmer)
14 Jun 00 12:10
Hi,
I am developing business tier objects in VB6 which are to be deployed using DCOM. I am using ActiveX Exe's for my business components. I have a lot of methods and their arguments need to be passed from the user interface tier to these business objects.

These arguments are not changed in the business tier. So I need not pass them ByRef. I want to know if there is any performance hit in passing arguments ByVal instead of ByRef?
Which option is better to achieve optimal performance???

Thank you
jatin
johnk (MIS)
14 Jun 00 12:58
We *always* use ByVal.  I understand that it avoids more than one set of exchanges between tiers for each time used.

Another time saver:  place all properties in an array, then pass the array as a variant.  Performance improvement is significant.

John Kisner
jlkisner@jlkisner.com

Nikolaj (Programmer)
15 Jun 00 2:27
I think that the performance conserning Time is improved if you use ByRef because its only pointers and not a copy of the parameter that is received! The thing that takes time is the copying of the parameter!!

But I think that is has to be a lot of function calls before the improvemnet is significant!


Nikolaj
calahans (Programmer)
15 Jun 00 4:12
I'd agree with John - pass by val where possible.

When programming in a distributed environment you need to reduce trips over the wire to a minimum. If you pass a reference to an object then you are going back and forth over the network each time you set/get a variable.

HTH

Cal


Nikolaj (Programmer)
15 Jun 00 4:15
Sure!!

Of course!! I didnt have that in mind! Was only thinking local objects!! Sure! Use ByVal when Distribudted apps!

Nikoalj
johnk (MIS)
15 Jun 00 8:50
This thread is another example of how the deployed environment affects COM & DCOM issues.  Here the issue is response performance, no issue except in distributed (DCOM) deployment.

There are related thoughts discussed in the Learning OOP forum.

John Kisner
jlkisner@jlkisner.com

jashy (Programmer)
15 Jun 00 9:14
Thank you all for your suggestions.

What Im doing is something similar. I've defined User Defined Types (UDT) in the middle tier. Now I want to accept these UDTs from the UI tier. However VB doesnt allow to accept the UDTs ByVal. They must be accepted ByRef. So a workaround is that in the method declaration in the middle tier, declare the argument as ByVal Variant. However while calling these methods from the UI take care of passing only the appropriate UDT. That way I am able to use UDTs instead of large no. of separate arguments and also able to accept them ByVal.

However the catch is that the user can pass any variant when a particular UDT is expected as the argument is defined as ByVal Variant.

Any one has a better suggestion?

Thanks
Jatin
Nikolaj (Programmer)
15 Jun 00 9:21
If you create the UDT in the Object in the middle tier too and uses this type as the parameter to the method visual basic, as I remeber, makes a Runtime Error if the parameter is of the wrong type. If you make a reference to the object in VB you actually can see that the paramtere has to be of the UDT!

Nikolaj
jashy (Programmer)
15 Jun 00 9:59
Nikolaj,
I've created the Public UDT in the middle tier. Now when I add a reference to the ActivX exe(MT) in the UI, the UDT is available in the UI.

Now, In the Middle tier the method accepts a Variant eg:
Public Function Test(ByVal arg1 as Variant) as Variant.

However, in the UI, I do something like this:

Dim udt1 as UDT
dim varRet as Varinat

 <populate the elements of the UDT>

varRet = MT.Test(udt1)


So Im passing the UDT in a Variant argument ByVal. This is possible. I tested with an ActiveX Exe and a Standard Exe.


Nikolaj (Programmer)
16 Jun 00 3:11
So that solved it or what??
jashy (Programmer)
16 Jun 00 11:54
Nikolaj,
Yes, sort of. Now I can pass the UDTs ByVal to the middle tier which accept them as a Variant.
So I achieved both:
1> Pass the arguments ByVal to improve the performance and
2> Use UDTs in the UI tier to avoid the clumsy method definitions involving large number of arguments.

Looks like I'll go with this only. The good part is that in the middle tier, after accepting the UDT as a Variant, you can store it back in a variable of type UDT.
jashy (Programmer)
19 Jun 00 11:51
Hi
Passing ByVal has the advantage over ByRef in the sense that it avoids network round trips.

However, in our application, we need to pass back the result of a SELECT statement on the table which might return more than 25,000 rows at once. We are thinking of passing the query result back to the UI tier in a Variant. (A 2 dimensional array containing the rows and columns of the SELECT statement).
While passing such large values, is it advisable to pass them ByVal? Will it not hog up the network when such large data is passed?

Im sure this is a question that will have to be solved in each DCOM application. I want to know how do you tackle this?

Thanks
Jatin
johnk (MIS)
19 Jun 00 12:14
Jatin,

You are confronting one of the significant performance issues with distributed applications.  Our architecture was designed 3 years ago and I expect there are better techniques now available, so maybe others will respond.

We try to keep our recordsets residing in the 2nd tier (or lower), then passing only selected records up to the UI tier.  When necessary for the UI logic to work directly with large data volumes (passing a whole customer table for display & selection) we pass only the required columns (maybe cust name & Number).  We use an array as a variant for the actual transfer.

Of course the use of browser architecture would eliminate the need for large data volumes to be transported to the UI tier.

John Kisner
jlkisner@jlkisner.com

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close