为什么窗口第一次打开文件的速度太慢了,还有更快的方法 [英] Why is windows so slow in opening files first time and is there a faster way

查看:261
本文介绍了为什么窗口第一次打开文件的速度太慢了,还有更快的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是Windows 7,64位专业版使用

考虑一个非常简单的循环

 {
std :: string Name = names->
HANDLE fileHandle = CreateFile(Name.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);

if(fileHandle == INVALID_HANDLE_VALUE)
{
throwFailed;
}

CloseHandle(fileHandle);



$ b $ p
$ b如果我在一个包含863个文件的目录上运行它, SECONDS,或25毫秒/文件。下一次169毫秒或0.19毫秒/文件。如果我只是使用find_file的时间,新鲜的目录是非常快的,约0.2毫秒/文件。虽然我在这里使用了CreateFile,但其他方法的结果相同。



当然,答案是文件缓存:windows必须缓存关于文件打开的信息。此外,它必须是磁盘访问,就像目录是在一个固态硬盘上,第一次和第二次打开大致相同。

现在这些硬盘上的寻找时间是只有9毫秒,所以没有人知道什么是WINDOWS当25毫秒的时间来打开/关闭文件只读没有阅读。但更重要的是,是否有可能加快这一进程。你可能会说25毫秒快,但我正在播放视频文件,所以我需要在33毫秒左右的时间读取,实际读取的数据是在30毫秒的范围内,所以开放的成本太高。 b
$ b

有关如何快速打开 * *加载文件的任何建议,我们将不胜感激。

解决方案

当你打开一个文件的时候,Windows很难做到这一点。我不是专家,但我可以提到文件系统维护(更新访问时间,日志等)和访问权限检查作为两个重要项目。不幸的是我不认为你可以做得更快。



当然,如果你不打算从文件中读取任何东西,你只是检查是否该文件存在或读取一些元数据,如修改时间,有没有更快的方式做到这一点,而不打开文件。

This is Windows 7, 64 bit, Professional using

Consider a very simple loop

for (i = 0; i < names->size(); i++)
{
    std::string Name = names->at(i);
    HANDLE fileHandle = CreateFile(Name.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

    if (fileHandle == INVALID_HANDLE_VALUE)
    {
        throw "Failed";
    }

    CloseHandle(fileHandle);
}

If I run this on a directory with 863 files, it takes slightly over 22 SECONDS, or 25 milliseconds/file. The next time 169 milliseconds or 0.19 milliseconds/file. If I just use find_file time on a fresh directory is very fast, about the 0.2 ms/file. Although I used CreateFile here, other methods yield the same results.

Of course the answer is file caching: windows must be caching the information about file open. Moreover, it must be disk access as if the directory is on an SSD, the first and second opens are about the same.

Now the seek time on these hard drives are only 9 ms, so does anyone know WHAT IS WINDOWS doing when it takes 25 milliseconds to open/close a file for only reading with NO reading. But more importantly, is it possible to speed this up. You might say 25 ms is fast, but I am playing video files so I need to read at about 33 ms and an actual read of data is in the 30 ms range, so the cost of opening is too high.

Any suggestions on how to open a **load of files quickly would be appreciated.

解决方案

Windows does a lot under the hood when you open a file. I'm no expert, but I can mention filesystem maintenance (updating the access time, journaling, etc.) and access permission checks as two important items. Unfortunately I don't think you can make this any faster.

Of course if you don't plan to read anything from the file, and you're just checking if the file exists or reading some metadata like its modification time, there are faster ways to do that without opening the file.

这篇关于为什么窗口第一次打开文件的速度太慢了,还有更快的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆