Note that there are some explanatory texts on larger screens.

plurals
  1. POFILE_FLAG_IO_BUFFERING slows down synchronous read operation
    primarykey
    data
    text
    <p>Reading a set of files with no buffering(skipping the file cache) using the flag FILE_FLAG_IO_BUFFERING should be faster than the normal reading(without using this flag). The reason for that to be faster is that 'no buffering' mechanism will skip the system file cache and will directly read into application's buffer. <br/> The application is run in cold environment (after disk defragmentation, machine restart) so that the system file cache is not cached with the concerned files before the run.<br/> This is from msdn documentation on these APIs and flags. <br/></p> <p>However, I experience a totally different performance behavior. I read a set of files synchronously one after the other, after the file handles have been created using the FILE_FLAG_IO_BUFFERING flag. The time it takes to read the set of files is 29 sec. Where as, if I had read normally without using this flag (again in the cold run of the application when file cache does not hold the concerned files), the time it takes is around 24 secs. </p> <p><strong>Details</strong>: <br/> Total number of files: 1939 <br/> Total file size(sum of all): 57 MB <br/> With FLAG_IO_NO_BUFFERING: 29 secs (time taken to read) <br/> Without FLAG_IO_NO_BUFFERING: 24 secs (time taken to read) <br/></p> <p>Here is the code that implements the read:</p> <pre><code>DWORD ReadFiles(std::vector&lt;std::string&gt; &amp;filePathNameVectorRef) { long totalBytesRead = 0; for(all file in filePathNameVectorRef) totalBytesRead += Read_Synchronous(file); return totalBytesRead; } DWORD Read_Synchronous(const char * filePathName) { DWORD accessMode = GENERIC_READ; DWORD shareMode = 0; DWORD createDisposition = OPEN_EXISTING; DWORD flags = FILE_FLAG_NO_BUFFERING; HANDLE handle = INVALID_HANDLE_VALUE; DWORD fileSize; DWORD bytesRead = 0; DWORD bytesToRead = 0; LARGE_INTEGER li; char * buffer; BOOL success = false; handle = CreateFile(filePathName, accessMode, shareMode, NULL, createDisposition, flags, NULL); if(handle == INVALID_HANDLE_VALUE) return 0; GetFileSizeEx(handle, &amp;li); fileSize = (DWORD)li.QuadPart; bytesToRead = (fileSize/g_bytesPerPhysicalSector)*g_bytesPerPhysicalSector; buffer = static_cast&lt;char *&gt;(VirtualAlloc(0, bytesToRead, MEM_COMMIT, PAGE_READWRITE)); if(buffer == NULL) goto RETURN; success = ReadFile(handle, buffer, bytesToRead, &amp;bytesRead, NULL); if(!success){ fprintf(stdout, "\n Error occured: %d", GetLastError()); return 0; } free(buffer); RETURN: CloseHandle(handle); return bytesRead; } </code></pre> <p>Please share your thoughts on the reason you think this code is running slower than when the FILE_FLAG_NO_BUFFERING is not used. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload