Click to See Complete Forum and Search --> : File reading optimization


Arun Mittal
August 31st, 2001, 01:35 AM
Hi ,

We are using the following API to read the files in VB. It is called for one scenario , around 11,000 times in the loop. This piece of code takes around 25 seconds out of total 30 seconds taken by the application. Can any of the parameter be altered to improve the performance or please tell us if any better method is available for reading.

(Every time the file path may be different so the file cannot be read once and kept in memory.)

l_hfile = CreateFile(str_DataPath, GENERIC_READ, FILE_SHARE_READ, ByVal CLng(0), OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0)

If l_hfile = -1 Then ' the file could not be opened
MsgBox "File '" & str_DataPath & "' Not found", vbCritical, "Error"
GoTo fi_ReadDataFile_Exit
End If

ReDim temp(DataLength - 1)

l_Retval = ReadFile(l_hfile, temp(0), DataLength, i_Numread, ByVal CLng(0))

l_Retval = CloseHandle(l_hfile)

Regards,
-arun