Reputation: 11425
I would like to exchange FILE* with HANDLE=CreateFile() to test the speed difference.
I am trying to change my code now.
Could somebody tell me how I chould change these 2 lines to reflect that I am dealing with a handle now and not a FILE* anymore?
fseek(myFile,iBytePos,SEEK_SET);
fread(&SomeValues[0],iByteCount,1,myFile);
I tried
LARGE_INTEGER l;
l.QuadPart=iBytePos;
SetFilePointer(myFile,l.LowPart,&l.HighPart,FILE_BEGIN);
DWORD dw;
BOOL result = ReadFile(myFile,&SomeValues[0],iByteCount,&dw,NULL);
but something is not correct. I must have gone wrong somewhere.
Thank you very much for the help!
Upvotes: 1
Views: 6503
Reputation: 51538
The Windows API equivalent for fread
is ReadFile
and for fseek
is SetFilePointer
. If you merely replace those calls the performance difference will be slim, if any. In contrast to fseek
, SetFilePointer
supports files > 2GB. If you don't need that the call is simply:
SetFilePointer(myFile, iBytePos, NULL, FILE_BEGIN);
You can speed up disk I/O using the Windows API by exploiting its greater flexibility. If you have lots of seek-read-seek-read operations you might benefit from using ReadFileScatter
instead.
Another potential route for optimization would be to use Asynchronous I/O. A comparison can be found at Synchronous and Asynchronous I/O.
Upvotes: 6
Reputation: 11047
For fseek
you can use SetFilePointerEx
or SetFilePointer
.
For fread
you can use ReadFile
or ReadFileEX
You can find help here
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365542(v=vs.85).aspx
Upvotes: 2