Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using FILE_ATTRIBUTE_TEMPORARY and FILE_FLAG_DELETE_ON_CLOSE

I am using the two flags FILE_ATTRIBUTE_TEMPORARY and FILE_FLAG_DELETE_ON_CLOSE while creating temporary files in my C++ application.

According to this blogđź•— there shouldn't be any file being created on the disk:

It’s only temporary

Larry Osterman, April 19, 2004

To create a “temporary” file, you call CreateFile specifying FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE in the dwFlagsAndAttributes 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.

But in my code the file is created and written to on disk (even for 1 KB data). Can someone confirm the exact functionality of these flags, and whether the files are created on disk or not?

like image 462
SVJ Avatar asked Mar 09 '11 07:03

SVJ


1 Answers

Later on in that same link, there is the quote:

If you exceed available memory, the memory manager will flush the file data to disk. This causes a performance hit, but your operation will succeed instead of failing.

Marking a file as temporary will tell the system it doesn't need to be on disk, but it doesn't prevent it from being put there, either.

like image 51
Jeremiah Willcock Avatar answered Sep 22 '22 02:09

Jeremiah Willcock