Fog Creek Software
Discussion Board




Pros-Cons of VB6 Implements acrossed threads?

I have a base class that is implemented by another class that resides in an Activex Exe project.  Are there any distinct advantages or disadvantages to this?

I also have questions about use of the With statement acrossed threads.  Do I bypass having to proxy each individual call between the threads by using it with an Exe Class? 

With regards to avoiding much proxying, am I better off trying to limit interaction to methods and and thus passing more parameters in lieu of setting properties?

Much thanks for any pointers from the group.

Wayne
Thursday, March 06, 2003

Not sure I follow...You said VB6, right?

When you said inherit, are you referring to implementing an interface in an ActiveEXe project? VB6 doesn't support class inheritance. (In the true sense of the word. I'm not referring to interface inheritance.)

Can you elaborate on your question about using the With statement? Multithreading in VB6 isn't really possible unless you do some rather, uh, unusual acrobats to make it happen. It certainly isn't something you can do "out of the box"

Now, your final question I think I can answer. Yes, you are typically much better of passing more parameters to a smaller number of methods and you certainly want to avoid setting properties on a remote object. The reason is that every time you access that remote object, the call has to be marshalled across the wire (or process boundary) and this chews up resources.

Hope that helped a little bit.

Go Linux Go!
Thursday, March 06, 2003

Apologies for the malformed request.  What I meant by Base class was actually more of an Abstraction class.  This probably made you think that I had said 'Inherit' when I actually said 'implements' (using the Implements keyword in VB).

Furthermore, what I meant by Thread actually should have been Process.  When you instantiate a class that resides in an Activex Exe VB creates the actual object in the process space of the Activex Exe.  Then it creates a 'proxy' object in the process space of the calling application and returns a pointer to IUnkown interface of the proxy object to the instantiating code.

The proxy object actually marshalls calls acrossed process spaces transparently to the calling app, so you are right about using functions instead of setting properties there for sure.

As for the With statement, I know that using it on an in-process/in-thread object makes VB only have to evaluate the object 1 time.  Like this:

With oObj
.Prop1 = "Val1"
.Prop2 = "Val2"
End With

I can see that this is still 2 Function calls as compared to: oObj.SetProps("Val1","Val2") However I was just wondering if using With on out of process Activex Exe objects did anything. 

I've decided that for out-of-process objects, I will always include an 'Initialize' type of method because this logically incurs less marshalling than setting properties.  For in-process objects I don't think their is a really great gain especially if I use With.

Wayne
Thursday, March 06, 2003

Wayne,

<quote>With regards to avoiding much proxying, am I better off trying to limit interaction to methods and and thus passing more parameters in lieu of setting properties?
</quote>

When dealing with out-of-proc calls (as you are) - definitely better to pass more parameters in one hit. Also, make sure you pass only data types that marshal well - which basically means base data types, arrays and disconnected ADO recordsets (no VBA collections for example).

Also http://peach.ease.lsoft.com/scripts/wa.exe?A0=visbas-l is a good place to discuss such issues.

<quote>
With oObj
.Prop1 = "Val1"
.Prop2 = "Val2"
End With
</quote>

AFAIK, from a performance standpoint, use of With like above gives you nothing. Where is it useful is in situations like:

Call ProjectName.ClassName.ClassName2.MethodName3
Call ProjectName.ClassName.ClassName2.MethodName4

which can be changed to:

With ProjectName.ClassName.ClassName2
    Call .MethodName3
    Call .MethodName4
End With

This basically means you only burrow down two levels ONCE (rather than twice) to get access to the instance of ClassName2. Since your example has no 'burrowing' it would not yield any performance benefit.

When thinking of With, think of it as declaring a variable and assigning a value to it, so:

Call ProjectName.ClassName.ClassName2.MethodName3
Call ProjectName.ClassName.ClassName2.MethodName4

could be changed to:

Dim x as ClassName2

set x = ProjectName.ClassName.ClassName2

call x.MethodName3
call x.MethodName4

set x = Nothing

That is essentially all With is doing...

Seeya

Matthew
Thursday, March 06, 2003

I think you should include the 'Initialize' method on every class needing it. The coding style should be the same for all object, and its ActiveX component implementation should not dictate it.

Thomas Eyde
Friday, March 07, 2003

Points taken, thanks for the replies.  I know this isn't the best forum for strictly technical questions, sorry about that.

Wayne
Friday, March 07, 2003

*  Recent Topics

*  Fog Creek Home