我正在尝试将大量数据写入我的SSD(固态硬盘).大量的我的意思是80GB.
我浏览网页寻求解决方案,但我想出的最好的是:
#include <fstream>
const unsigned long long size = 64ULL*1024ULL*1024ULL;
unsigned long long a[size];
int main()
{
std::fstream myfile;
myfile = std::fstream("file.binary", std::ios::out | std::ios::binary);
//Here would be some error handling
for(int i = 0; i < 32; ++i){
//Some calculations to fill a[]
myfile.write((char*)&a,size*sizeof(unsigned long long));
}
myfile.close();
}
Run Code Online (Sandbox Code Playgroud)
使用Visual Studio 2010进行编译并完全优化并在Windows7下运行,此程序最大可达20MB/s.让我感到困扰的是,Windows可以将文件从其他SSD复制到此SSD,速度介于150MB/s和200MB/s之间.所以至少快7倍.这就是为什么我认为我应该能够更快.
我有什么想法可以加快我的写作速度?