title: calling CreateFile, specifying FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE
body: <p>Before I describe my problem, here is a description of the C++ program I'm writing:</p>
  
  <ul>
  <li>The purpose of my program is to create file on RAM memory.</li>
  </ul>
  
  <p>I read that if specify <code>FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE</code> when creating file it will be loaded direct to the RAM memory.</p>
  
  <p>One of blogs that talk about is this one: </p>
  
  <blockquote>
    <h2><a href="http://blogs.msdn.com/larryosterman/archive/2004/04/19/116084.aspx" rel="nofollow noreferrer">It’s only temporary</a> <sup><a href="https://archive.fo/kMndX" rel="nofollow noreferrer"></a></sup></h2>
    
    <p>Larry Osterman, April 19, 2004</p>
    
    <p>To create a “temporary” file, you call CreateFile specifying <code>FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE</code> in the <strong>dwFlagsAndAttributes</strong> attribute.  This combination of bits acts as a hint to the filesystem that the file data should never be flushed to disk.  In other words, such a file can be created, written to, and read from without the system ever touching the disk.</p>
  </blockquote>
  
  <p>I have built a mini-program, but it doesn't achieve the goal. Instead, it creates a file on the hard-drive, in directory I specify.</p>
  
  <p>Here's my program:</p>
  
  <pre><code>void main ()
  {
     LPCWSTR str = L"c:\\temp.txt";
     HANDLE fh = CreateFile(str,GENERIC_WRITE,0,NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,NULL);   
  
     if (fh == INVALID_HANDLE_VALUE)
     {
        printf ("Could not open TWO.TXT");
        return;
     }
  
     DWORD dwBytesWritten; 
     for (long i=0; i&lt;20000000; i++)
     {
        WriteFile(fh, "This is a test\r\n", 16, &amp;dwBytesWritten, NULL);
     }
  
     return;
  }
  </code></pre>
  
  <p>I think there problem in <a href="https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew" rel="nofollow noreferrer"><strong>CreateFile</strong></a> function, but I can't fix it. Please help me.</p>