Monday, October 4, 2010

Prefer CreateFile API with FILE_FLAG_DELETE_ON_CLOSE for temporary files

Tip - Prefer CreateFile API with FILE_FLAG_DELETE_ON_CLOSE for temporary files.

Detail - The CreateFile API call accepts several flags which affect how a file is created or opened. One of these flags, FILE_FLAG_DELETE_ON_CLOSE, specifies that the file will be deleted when the last handle to it is closed. A common activity for applications is to create temporary files. If the application terminates abnormally, these files may not be deleted, potentially wasting of disk space. But if CreateFile API is called with FILE_FLAG_DELETE_ON_CLOSE that deletes the file when all handles to it are closed, which will be perfect for temporary file scenarios.

Reference -http://msdn2.microsoft.com/en-us/library/aa363858.aspx


Posted by - Sobhita Mercy E

No comments:

Post a Comment