这是下载地址
http://pan.baidu.com/s/1eQfNx1g
有个问题,就是这个软件计算大文件速度也很快,而且我看了下内存也只有1M多点
IO读取速度很快,按理说是每次读一块数据去计算MD5,请问这种读取是如何实现的,貌似没有占用多余的内存
string FileDigest(const string &file) {
ifstream in(file.c_str(), ios::binary);
if (!in)
return "";
streampos pos = in.tellg(); // save current position
in.seekg(0, ios::end);
cout << "file length =" << (unsigned long)in.tellg() << endl;
unsigned long dwLen = in.tellg();
in.seekg(pos); // restore saved position
unsigned long dwLenDon = 0;
MD5 md5;
std::streamsize length;
//char buffer[1024000];
char* buffer = new char[1024*1024*100];
while (!in.eof()) {
in.read(buffer, 1024*1024*100);
length = in.gcount();
if (length > 0)
md5.update(buffer, length);
dwLenDon+=length;
cout<< "完成率:" << dwLenDon*100/dwLen<<endl;
}
in.close();
return md5.toString();
}
这是我写的小程序,小文件还好,大型文件就慢了
------解决思路----------------------
使用内存映射文件可以减少缓冲区拷贝,提高访问文件的效率。而 MD5 算法本身也是可以优化提高速度的。
你要做优化,先测试那部分影响你的效率了,再针对那一部分做。