c++ - 我可以一次将整个 NTFS 目录树读入 RAM 吗?

标签 c++ linux windows performance

由于这个问题没有产生有用的答案和一些评论,请参阅我的其他问题,它得到了答案:How exactly "Everything Search" can give me immediately searchable list of 2bln files on my 4TB HDD in less than 10 seconds?

我知道读取目录的唯一方法是递归地下降到每个目录,但如果我想快速找到整个磁盘上的任何位置,这太慢了。

有一个Windows程序“Everything Search”http://www.voidtools.com/这比我想象的递归下降速度要快(它在 10 秒内读取 4TB HDD 上近 20 亿个文件的文件名)。

我知道我可以提前构建索引,但是可以通过一次操作将磁盘的整个目录树读入内存并在那里解析来完成吗?

编辑

由于我的问题被证明令人困惑,这就是我想做的:

https://msdn.microsoft.com/en-us/library/07wt70x2(v=vs.110).aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

// For Directory::GetFiles and Directory::GetDirectories 
// For File::Exists, Directory::Exists 
using namespace System;
using namespace System::IO;
using namespace System::Collections;

// Insert logic for processing found files here. 
void ProcessFile( String^ path )
{
   Console::WriteLine( "Processed file '{0}'.", path );
}


// Process all files in the directory passed in, recurse on any directories  
// that are found, and process the files they contain. 
void ProcessDirectory( String^ targetDirectory )
{

   // Process the list of files found in the directory. 
   array<String^>^fileEntries = Directory::GetFiles( targetDirectory );
   IEnumerator^ files = fileEntries->GetEnumerator();
   while ( files->MoveNext() )
   {
      String^ fileName = safe_cast<String^>(files->Current);
      ProcessFile( fileName );
   }


   // Recurse into subdirectories of this directory. 
   array<String^>^subdirectoryEntries = Directory::GetDirectories( targetDirectory );
   IEnumerator^ dirs = subdirectoryEntries->GetEnumerator();
   while ( dirs->MoveNext() )
   {
      String^ subdirectory = safe_cast<String^>(dirs->Current);
      ProcessDirectory( subdirectory );
   }
}

int main( int argc, char *argv[] )
{
   for ( int i = 1; i < argc; i++ )
   {
      String^ path = gcnew String(argv[ i ]);
      if ( File::Exists( path ) )
      {

         // This path is a file
         ProcessFile( path );
      }
      else 
      if ( Directory::Exists( path ) )
      {

         // This path is a directory
         ProcessDirectory( path );
      }
      else
      {
         Console::WriteLine( "{0} is not a valid file or directory.", path );
      }

   }
}

我想获得相同的信息,但不想多次调用Directory::GetDirectories。我正在寻找的解决方案无论如何看起来都不像这段代码。此代码只是说明我想要读取磁盘的哪些信息(目录中所有文件的名称),而不是我想要的方式(我不想要递归和与目录一样多的系统调用)。

编辑2(对于认为这个问题太宽泛的人):

我问如何在 Windows 或 Linux 操作系统上执行此操作。我会接受任何语言的答案,因为我最感兴趣的是需要进行哪些系统调用(以及如何解析这些调用的结果)才能将整个驱动器的 NTFS 目录树放入 RAM,而驱动器上每个目录的系统调用次数少于一次。

我也会接受指向我的 Windows 或 Linux 库的答案,该库正是执行此操作的。

最佳答案

如果你有足够的内存,那么就继续吧。但我建议您分部分加载磁盘而不是整个磁盘,这也会提高您的时间效率。

关于c++ - 我可以一次将整个 NTFS 目录树读入 RAM 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32551089/

相关文章:

c++ - 我可以使用 std::vector 作为预分配(原始)数组的外观吗?

c++ - 在 64 位 Ubuntu 中使用 pthread 从 void* 转换为 int

python-3.x - 如何在 Arch Linux 中安装最新版本的 Python 和 pip?

windows - 为什么 git 要我输入密码?

windows - Haskell 32 位程序在 64 位 Windows 上卡住

c++ - 如何从 C++ 重新启动 Mac OS

c++ - 如何限制在 C++ AMP 中执行操作的线程数

c - 如何在您的 makefile 中链接静态 glibc

linux - 如何更好地配置 linux/CPU 以运行大型软件 (NUMA)

c++ - 有没有一种方法可以使 MainWindow 窗口任务栏图标闪烁?