title: Why are odd-sized fread requests split in two?
body: <p>I noticed that on Windows every time I issue an unbuffered fread() request with an odd length, it's split into 2 requests (as observed through procmon):</p>
  
  <p>a) fread for my requested length-1</p>
  
  <p>b) 2-byte fread for the last byte</p>
  
  <p>This has an obvious performance overhead like 2 kernel requests instead of one etc.</p>
  
  <p>Sample code ran on Windows 10:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(int argc, char* argv[]) {
      FILE* pFile;
      char* buffer;
  
      pFile = fopen(argv[0], "rb");
  
      setbuf(pFile, nullptr);
  
      size_t len = 3;
      buffer = (char*)malloc(sizeof(char)*len);
  
      if (len != fread(buffer, 1, len, pFile)) { fputs("Reading error", stderr); exit(3); }
  
      free(buffer);
      fclose(pFile);
      return 0;
  }
  </code></pre>
  
  <p>This results in the following procmon reported calls:</p>
  
  <p>ReadFile c:\work\cpptry\Debug\cpptry.exe   SUCCESS   Offset: 0, Length: 2, Priority: Normal</p>
  
  <p>ReadFile c:\work\cpptry\Debug\cpptry.exe   SUCCESS   Offset: 2, Length: 2</p>
  
  <p>It seems as if Windows is incapable of issuing odd-sized requests to the file system. 
  What's up with that?</p>