kov*_*and 10 memory windows windows-10
我制作了一个小型 C++ 程序,将一个 2.7KB 的小 png 文件复制 100 万次。这是我的记忆在副本之前的样子:
复制程序关闭后我等了几分钟,也许内存使用量会下降,但只下降了500MB。
如果我再运行复制程序几次,那么 RAM 使用率会更高,但不会超过此点:
这是复制程序代码:
//called with loopSize=1'000'000
void TestFileCopy(const string& sourcePath, const string& destFolder, int loopSize)
{
int counter = 0;
while (counter < loopSize)
{
std::ifstream source(sourcePath, std::ios::binary);
if (source.fail())
throw std::runtime_error("File not found: " + sourcePath);
string destPath = destFolder + std::to_string(counter) + ".png";
std::ofstream dest(destPath, std::ios::binary);
dest << source.rdbuf();
source.close();
dest.close();
if (source.fail())
throw std::runtime_error("Error reading file: " + sourcePath);
if (dest.fail())
throw std::runtime_error("Error writing file: " + destPath);
++counter;
}
}
Run Code Online (Sandbox Code Playgroud)
Roh*_*pta 11
我认为这是因为文件被操作系统缓存了。删除文件后,就不再需要缓存。而且记忆是可以恢复的。
归档时间: |
|
查看次数: |
1193 次 |
最近记录: |