Link to home
Start Free TrialLog in
Avatar of kayee
kayee

asked on

connector class

I have created a connector class in vb6 that will return me an reference to an atl object.  The atl object is full of collections.  When I spin through the collections using the connector class the performance seems to be 20 times worse than when connecting to the object directly.  Can I speed up the performance when using the connector class??  The
connector class was modeled after the MSDN "Coffee" example!  Here is how I call the connector and loop.
 
Private oC As scAtlObject
Private oConnector As clsConnector
 
Private Sub cmdConnect_Click()
    Screen.MousePointer = vbHourglass
 
    Set oConnector = New clsConnector
    Set oC = oConnector.clsAtlConnector.oC
 
    Screen.MousePointer = vbDefault
End Sub
 
Private Sub cmdConnectDirect_Click()
 
    Screen.MousePointer = vbHourglass
 
    Set oC = new scAtlObject
    oC.Load
    Screen.MousePointer = vbDefault
 
End Sub
 
Private Sub cmdLoop_Click()
    Dim oTemp as oT
    Dim oTemp2 as oT2
    Dim lStart as Long
    Dim lEnd as Long
 
    lStart = GetTickCount()
    For Each oTemp in oC
        For Each oTemp2 in oTemp
           
        Next
    Next
    lEnd = GetTickCount()
    MsgBox "Time(ms): " & lEnd - lStart
End Sub
Avatar of dhodge
dhodge

Using For Each is perhasps the most obvious time waster here.  It has to establish the item count each time and convert the object into the required type.

Firstly try taking a count before the loop and looping

ncount = oC.Count
for i = 1 to nCount

Do this for both loops.  Then when using the individual object reference it with the item property.

eg.

ncount = oC.Count
for i = 1 to nCount
    nInnerCount = OTemp.Count
    for n = 1 to nInnerCount
        set OTemp2 = oC(i).item(n)
        oTemp2.DoSomething
    next
next
Avatar of kayee

ASKER

That is a good point, but If I use the existing for each logic the time to loop through my atl object when connected using the connector class is about 5 secs.  I connect directly to my atl object and loop it takes about 20 milliseconds.  Why is this so slow and what can I do to get the same performance as connecting directly?
Late binding?
Fastest acces is via early binding (vtable)
Avatar of kayee

ASKER

I use early binding, My atlobject and my activex exe connector are referenced in my vb project.
I don't see in your code accessing any property.
How are you accesing properties? How you do it when accessing object directly?
Avatar of kayee

ASKER

When I connect directly, I create a instance of the atlobject by settin oC = new scAtlObject.  Then I can call the method oC.Load which will load all of the collections.  
Then I spin through the collections without accessing any properties to make sure the speed issue isn't in one of the properties.
Std com objects are slow, ATL is fast. Take any dummy ATL object and any COM object and you will see the same time differences. That is why you took the time to write it in ATL isn't it...
Avatar of kayee

ASKER

I need some way to have multiple vb clients connect to the existing atl object with good performance.  Is there some other way to do this?
ASKER CERTIFIED SOLUTION
Avatar of bshuler072699
bshuler072699

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial