Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing object as parameter in a method

Status
Not open for further replies.

jamsek19

Programmer
Feb 4, 2002
35
SI
Hello.
We know that we cannot pass private User defined types (UDT) as a parameter to one method in AciveX DLL and for example, ADODB.Recordset can. Therefore I was wondering, I will pass my own object created from one class which has just properties, as a parameter.
Can someone tell me if there's a lot of overhead for VB and COM (to decrease performance), if I pass parameter this way?
Thanks in advance.
 
passing objects to COM objects is possible but it makes your objects slower and less scalable. Most Objects, besides the ADODB.RecordSet, pass only the interface across and each access of the object causes an RPC back to to the Process that created the parameter object. If you have many parameters to pass across there are a few ways of doing it.
Here are just some suggestions.
1) Pass them as 1 string and have a constructor function on your client end to make the string and a parser on your COM object end to break it back down
2) place each property in a propertybag, throw that property bag in to a byte array then the byte array into a string and pass that over then reverse the process. (though I'm not a fan of this method it is valid and well documented around the place)
3) create a dynamic Recordset and populate it and pass it across. This take up a bit more resources but since Recordsets actually marshell the entire object across it is still better performance than passing a custome VB object across.

Remember this might sound complicated but you always have tradeoffs. Often having simple code that looks neat actually cost performance behinds the scene. Less visible code does not mean faster code. You have to understand what that 1 line of code your program is doing does behind the scene.
 
Thanks SemperFiDownUnda. I imagine something like that. In this case, I also prefer the third way - by recordset.
Thanks again
Andrej
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top