Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best Practices
Message
From
08/02/2013 13:10:11
Mike Sue-Ping
Cambridge, Ontario, Canada
 
 
To
08/02/2013 12:59:26
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01565478
Message ID:
01565509
Views:
83
Thank you for the information. Do you know if VFP9 did anything to change your test results?

Mike

>Here's what we said about this subject in the Hacker's Guide:
>
>--------
>VFP 6 also introduced a new way to create objects. The NewObject() function lets you instantiate objects without worrying about whether you've pointed to the class library ahead of time—instead, you just include the library name in the call. CreateObject(), of course, needs the library in the current list with either a Set ClassLib or SET PROCEDURE ahead of time.
>
>So which way is faster? As usual, the answer is "it depends." With VCX-based classes, if you can issue Set ClassLib just once and then instantiate classes from that library repeatedly, CreateObject() is the way to go. It's anywhere from four to ten times faster than calling NewObject() with the class library. On the other hand, if you need to load the library each time, the Set ClassLib/CreateObject() pair is in the same ballpark as NewObject().
>
>How about for classes written in code? In that case, issuing a single SET PROCEDURE and calling CreateObject() repeatedly is five to ten times faster than either NewObject() or the SET PROCEDURE/CreateObject() pair, which are pretty similar.
>
>In the VFP 6 version of this book, we reported that instantiating a coded class was a little faster than instantiating a VCX-based class, but not enough faster to wipe out the benefits of developing classes visually. In VFP 7, we see varying results: Sometimes the coded class instantiates faster, while at other times, the VCX-based class is faster. Bottom line: We'll stand by our advice to develop visual objects visually.
>
>We're not really surprised that NewObject() is generally slower than CreateObject(). It's doing a lot of work behind the scenes. Here's the sequence: Save the names of all open class libraries, then close them. Next, open the specified class library, instantiate the object, and close the class library. Finally, reopen all the formerly open class libraries. Whew, that's a lot of files to find and mess with. Of course, we don't understand why VFP doesn't check whether the specified library is in the current list before going to all that trouble—seems to us it could speed up NewObject() considerably, in most cases.
>
>We tested and found no performance penalty for having a lot of class libraries open, no matter where in the list the class you're instantiating is found. So the rule here is to think about how you're going to do things before you write the code and, if possible, just keep open the class libraries you use a lot. Then use NewObject() for the one-shots, the classes from libraries you need only once in a while.
>---
>
>All that said, I use NewObject() pretty much all the time because I don't like to rely on settings.
>
>Tamar
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform