Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why is 2nd file-to-array is 10x slower
Message
From
04/02/2011 21:01:41
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
04/02/2011 14:51:54
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01498822
Message ID:
01498856
Views:
44
After reading the file into a variable with filetostr(), it should also be possible to read one line at a time with mline(). I suppose this will be quite fast if you use the _mline system variable.

Here is an example from the help file (topic mline()):
STORE 0 TO _MLINE             && Reset _MLINE to zero
STORE SECONDS( ) TO gnBegin      && Beginning time
FOR count = 1 TO gnNumLines      && Loop for # of lines in memo field
   ? MLINE(notes, 1, _MLINE)      && Display each line
NEXT
? STR(SECONDS( ) - gnBegin, 4, 2) + ' seconds'   && Total time
Here, too, the idea is to read the file sequentially.

>Problem: Reading a file into an array takes ten times longer after the first time the program is run. (Quitting VFP and starting over is the only solution right now.)
>
>The file is about 55MB in size. The program is a simple "PRG" (no forms, no tables, etc.)
>
>Because the file is so large, I found it better to skip reading it into a string and then into an array.
>
>The code is question is at the beginning of the PRG file, after some initial definitions and is:
>
>nStart = SECONDS()
>* read file into array
>nLines = ALINES(aIn, FILETOSTR(cInputFile))
>? 'the time to array = ' + TRANSFORM(SECONDS() - nStart) + ' seconds'
>
>
>The first time the program is executed, the file reads into the array in 3 seconds. Each time after that it takes 30-40 seconds.
>
>I have tried these things:
>
>CLEAR ALL
>RELEASE ALL LIKE *
>* purge cached memory
>SYS(1104)
>DIMENSION aIn[1]
>
>... at the beginning of the program, but there is no difference. I'm wondering if there is a file buffer that needs emptying, but then I'd think the read would get longer each time but it's approximately the same for every execution after the first.
>
>Suggestions please -- including different ways to approach this application.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform