【发布时间】:2009-12-28 17:43:07
【问题描述】:
这是我正在使用的代码:
using (StreamWriter output = new StreamWriter(Path.Combine(masterdestination, "Master.txt")))
{
string masterfolders = sourcefolder1;
string[] filess = Directory.GetFiles(masterfolders, "*.txt");
foreach (string file in filess)
{
output.WriteLine(Path.GetFileName(file));
}
}
此代码将搜索用户指定目录中的所有文件以查找任何 txt 文件。这些目录有时包含 200 万个文件。
在此进程运行时对其进行监控,我发现它的内存使用量攀升至 800MB。有没有办法可以保持这个过程的速度并限制它使用的内存?还是让它读取并转储并继续?哈希表?任何想法都会很棒。
【问题讨论】:
-
为什么 1mb 的内存使用是个问题?超过一百万个文件?
标签: c#