Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CreateObject() vs NewObject()
Message
From
23/08/2007 10:27:42
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
23/08/2007 08:58:31
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP1
Miscellaneous
Thread ID:
01249678
Message ID:
01249852
Views:
29
Hi Dragan

>>>>NewObject() is slower then CreateObject()
>>>
>>>Because it needs to find the file (even internally)?
>>
>>No, because NEWOBJECT() works by first saving a list of all of the open class libraries, then closing them, then creating the object, then reopening all of the previously open class libraries. Weird I know, but that's how it works.
>
>Ah but then we'd have to benchmark pure newobject() and no classlibs set vs Set ClassLib/Set Procedure and CreateObject(). If there were none set (and none to reopen) then its speed may be the same.

I often find myself wondering why we focus so hard on this level of detail. Best practice says we're supposed to make a component (UDF or class) to encapsulate design decisions of this kind.

A factory object IMO (being the ultimate in flexibility) should be used to instantiate objects. It would be the place to decide if we should use newobject or createobject - as hardcoding classes limits flexibility.

Further it would be a fantastic place to add code that checks to see if the class / procedure is already opened before opening it again.

IF NOT "VCXNAME" $ SET("CLASSLIB")
SET CLASSLIB TO VCXNAME ADDITIVE
ENDIF
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform