Using FILE_ATTRIBUTE_TEMPORARY and FILE_FLAG_DELETE_ON_CLOSE

I use the two flags FILE_ATTRIBUTE_TEMPORARY and FILE_FLAG_DELETE_ON_CLOSE when creating temporary files in my C ++ application.

According to this blog, there should not be any files on the disk :

This is only temporary.

Larry Osterman, April 19, 2004

To create a "temporary" file, you call CreateFile, specifying FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE in dwFlagsAndAttributes attribute. This combination of bits serves as a hint to the file system that file data should never be written to disk. In other words, such a file can be created, written and read without the system ever touching the disk.

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

+10
source share
2 answers

Later in the same link there is a quote:

If you exceed the available memory, the memory manager will clear the data file to disk. This causes performance, but your operation will succeed, not fail.

Marking the file as temporary will indicate to the system that it should not be on the disk, but it does not prevent it from being placed there.

+11
source

It simply says that the file will never be flushed to disk. This means that although it exists on your file system, it will never be physically stored on your hard drive. The file system will show it with the actual size and all.

+8
source

Source: https://habr.com/ru/post/890216/


All Articles