>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.
I suggest to use low-level fgets function instead here. It should be quicker than reading this huge file into array and ALINES.
If it's not broken, fix it until it is.
My Blog