I have seen that Windows system use temporary files to increase the performance of some tasks. Those files are marked with the 0x100 attribute when i look at them. I have got the following text from Microsoft: "
By using CreateFile() with the FILE_ATTRIBUTE_TEMPORARY flag, you let the system know that the file is likely to be short lived. The temporary file is created as a normal file. The system needs to do a minimal amount of lazy writes to the file system to keep the disk structures (directories and so forth) consistent. This gives the appearance that the file has been written to the disk ."
Any example of creating such temporary file using Delphi?
Thanks.
[EDIT]
Complementary question: what could be the context of using such file, example, could it be used for a log system. the log being this file with the temp attribute? Would it be faster and less memory prone when log get very large?
[EDIT]
Ok i have create file using solution given by schnaader below with the FILE_ATTRIBUTE_TEMPORARY:
hMyFile := CreateFile(FileName,
GENERIC_WRITE,
0,
nil,
CREATE_ALWAYS,
FILE_ATTRIBUTE_TEMPORARY,
0);
Such file get the 0x120 attribute when created. Thus a temporary file according to system.
I have also create a file with the FILE_FLAG_DELETE_ON_CLOSE flag (see this article by L. Osterman).
So:
hMyFile := CreateFile(FileName,
GENERIC_WRITE,
0,
nil,
CREATE_ALWAYS,
FILE_FLAG_DELETE_ON_CLOSE,
0);
This file gets no attribute and the file is automatically deleted when the application is closed or destroyed.
I did not find how to combine the attribute and the flag. Any idea?
Thanks