INFO: Tips to Improve Performance While Using OLE Servers

Last reviewed: February 26, 1997
Article ID: Q138072
4.00 WINDOWS kbole

The information in this article applies to:

  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SUMMARY

This article lists tips to keep in mind when instantiating an OLE server object, when calling a method, or when using a property of the object.

MORE INFORMATION

Tip One

Here are two ways in which an object could be created using early binding:

  • Dim x As New MyClass Call x.MyMethod

    -or-

  • Dim x As MyClass Set x = New MyClass Call x.MyMethod

The latter code is faster and more efficient because it creates an instance of the object only while executing the Set statement. The former code doesn't instantiate the object until the statement that calls a method of the object.

In the former code, each call to a member of an object checks to see if it has been instantiated. If not it is instantiated at that point, the call is made. In the latter code, no such check is made, so it is faster. It is the responsibility of the application developer to ensure that an object variable has been properly instantiated before calling any of its members.

Another thing to keep in mind is that the former code guarantees that you always have a reference to an object. Therefore, even if you:

   Set x = Nothing

and later check:

   If x Is Nothing Then

x is instantiated at that point. Such a check will always return a value of False. Whereas in the latter code, you are always free to set x to Nothing and check for it correctly later.

Tip Two

While calling members of an out-of-process OLE Server such as an OLE EXE server, if you need to make repetitive calls to members that return quickly (for example, members like the height property of the Form object that don't use many instruction cycles), it will be faster to call a single method that bundles all these other "lightweight" properties into an array or returns them as parameters to this single method. This is because the time taken by the marshalling code for a cross-process call to execute is much more than what is needed to perform the task that the member does.


KBCategory: kbole
KBSubcategory: IAPOLE vb4win vb4all
Additional reference words: optimization speed quick 4.00
Keywords : IAPOLE vb4all vb4win kbole
Version : 4.00
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 26, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.