加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 如何创建临时文件(0x100)以加速应用程序

发布时间:2020-12-15 04:31:11 所属栏目:大数据 来源:网络整理
导读:我已经看到 Windows系统使用临时文件来提高某些任务的性能.当我查看它们时,这些文件标有0x100属性.我收到了微软的以下文字:“ By using CreateFile() with the FILE_ATTRIBUTE_TEMPORARY flag,you let the system know that the file is likely to be short
我已经看到 Windows系统使用临时文件来提高某些任务的性能.当我查看它们时,这些文件标有0x100属性.我收到了微软的以下文字:“

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
.”

使用Delphi创建这样的临时文件的任何例子?

谢谢.

[编辑]

补充问题:可能是使用此类文件的上下文,例如,它可以用于日志系统.日志是这个文件的临时属性?当日志变得非常大时,它会更快,更少内存吗?

[编辑]

好的,我使用下面的schnaader给出的解决方案使用FILE_ATTRIBUTE_TEMPORARY创建文件:

hMyFile := CreateFile(FileName,GENERIC_WRITE,nil,CREATE_ALWAYS,FILE_ATTRIBUTE_TEMPORARY,0);

这样的文件在创建时获得0x120属性.因此根据系统的临时文件.

我还创建了一个带有FILE_FLAG_DELETE_ON_CLOSE标志的文件(see this article by L. Osterman).

所以:

hMyFile := CreateFile(FileName,FILE_FLAG_DELETE_ON_CLOSE,0);

此文件没有属性,并且在关闭或销毁应用程序时会自动删除该文件.

我没有找到如何组合属性和标志.任何的想法?

谢谢

解决方法

那么,使用CreateFile()方法怎么样?
var
  FileName : PChar;
  hMyFile : THandle;

...

hMyFile := CreateFile(FileName,0); 

if (hMyFile = INVALID_HANDLE_VALUE) then begin
  // Error
end;

...

CloseHandle(hMyFile);

要将标志与FILE_FLAG_DELETE_ON_CLOSE结合使用,请使用或:

hMyFile := CreateFile(FileName,FILE_ATTRIBUTE_TEMPORARY or FILE_FLAG_DELETE_ON_CLOSE,0);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读