Monday, February 25, 2008 3:43 PM
kkchan
Use NEWOBJECT() function with care
I like to use NEWOVBJECT() to initiate object so that I don't have to care about SET PROCEDURE TO / SET CLASSLIB TO.
Recently, I am re-writing my company application update program. That is a method that loop thru all the necessary directory and files and store the file info (as per array content returned by ADIR()) into collection. The file details are stored as object based (I have class called FileInfo). FileInfo object is created using NEWOBJECT("FileInfo", "FileInfo.prg") function.
During the testing, I found the program takes 6.6 secs to check for 1200 files. The code of NEWOBJECT("FileInfo", "FileInfo.prg") was hit 2400 times due to the same function being called for source and target file. Each hit take average 0.0027 secs. That meant program spent 6.47 secs just to create FileInfo objects. This is unacceptable.
I changed my code SET PROCEDURE TO FileInfo.prg ADDITIVE at program startup and replace NEWOBJECT() with CREATEIBJECT(). Hey, the program now only take 1.5 secs to do the same thing. Therefore, we got to use NEWOBJECT() with care otherwise it might kill your application.
Technorati tags:
FoxPro,
Visual FoxPro