创建了一个BIN文件a.bin,将原先的一个b.BIN文件内容拷贝到buffer 中,再拷贝到a.bin中,然后再将a.bin文件在Edit(m_BinShow)控件中显示,当创建的文件b.BIN比较大时(即m_UintFlash较大),
CPU的占用率达到97%,造成系统死机,请问各位高手大虾怎样解决?
谢谢!!BYTE writeBuf[65536];
BYTE buffer[65536];for(UINT i = 0; i < 65536; i++)
{
writeBuf[i] = 0;
}UINT m_UintFlash = 32;
UINT m_filelength =2048;CFile outfile;
outfile.Open(a.BIN, CFile::modeCreate | CFile::modeReadWrite |
CFile::typeBinary, NULL );outfile.WriteHuge(buffer, m_filelength);
UINT m_l;
m_l = m_UintFlash * 1024 - m_filelength;outfile.SeekToEnd();
outfile.WriteHuge(writeBuf, m_l - 2);outfile.Close();
CFile newfile;
newfile.Open(a.BIN, CFile::modeRead | CFile::typeBinary, NULL);
m_filelength = newfile.GetLength();newfile.ReadHuge(buffer, m_filelength);CString str;
UINT count = 0;
str.Format("%08X",count);
m_BinShow += str +":";
for(UINT i= 0; i < m_filelength; i++)
{
str.Format("%02X",buffer[i]);
m_BinShow += str + " ";
count++;
m_ProGress.SetPos(i);
if(count == 16) //控制换行
{
m_BinShow +="\r\n";
str.Format("%08X",i+1);
m_BinShow +=str + ":";
count = 0;
UpdateData(FALSE);
}}
newfile.Close();
CPU的占用率达到97%,造成系统死机,请问各位高手大虾怎样解决?
谢谢!!BYTE writeBuf[65536];
BYTE buffer[65536];for(UINT i = 0; i < 65536; i++)
{
writeBuf[i] = 0;
}UINT m_UintFlash = 32;
UINT m_filelength =2048;CFile outfile;
outfile.Open(a.BIN, CFile::modeCreate | CFile::modeReadWrite |
CFile::typeBinary, NULL );outfile.WriteHuge(buffer, m_filelength);
UINT m_l;
m_l = m_UintFlash * 1024 - m_filelength;outfile.SeekToEnd();
outfile.WriteHuge(writeBuf, m_l - 2);outfile.Close();
CFile newfile;
newfile.Open(a.BIN, CFile::modeRead | CFile::typeBinary, NULL);
m_filelength = newfile.GetLength();newfile.ReadHuge(buffer, m_filelength);CString str;
UINT count = 0;
str.Format("%08X",count);
m_BinShow += str +":";
for(UINT i= 0; i < m_filelength; i++)
{
str.Format("%02X",buffer[i]);
m_BinShow += str + " ";
count++;
m_ProGress.SetPos(i);
if(count == 16) //控制换行
{
m_BinShow +="\r\n";
str.Format("%08X",i+1);
m_BinShow +=str + ":";
count = 0;
UpdateData(FALSE);
}}
newfile.Close();
memset(buff,0,sizeof(buff));
outfile.Open(a.BIN, CFile::modeCreate | CFile::modeReadWrite |
newfile.Open(a.BIN, CFile::modeRead | CFile::typeBinary, NULL);
2.使用memset.
3.建立一个大小为len,内容全为0的文件使用outfile.SetLength(len);
4.对于这种将读文件的进度显示到进度条上的程序,如果不想为读文件
单独开一个线程,那就在for()内加一个Sleep()吧!将一部分时间空出
给CPU.
建议一开始不要将所有内容写入
等到用户翻页到某页时再从文件读该页并显示