关于DEBUG中断,内存不足问题!!!
程序如下:
前面省略。。。。。。
xtfdata是一个结构体。
CFile file0;
file0.Open(emfilename,CFile::modeWrite|CFile::modeCreate|CFile::modeNoTruncate);
buchang4=4;
buchang1=1;
buchang2=2;
buchang8=8;
CString str;
double pai=3.14159265358979323846;
file.Open(filename,CFile::modeRead);
tlength=file.GetLength();
file.Seek(0,CFile::begin);
file.Read(&data1,buchang1);
memcpy(&xtfdata.FileFormat,&data1,buchang1);
CString test;
test.Format("%d",xtfdata.FileFormat);
texttest=CString("XTFFileHEADER")+ CString("\r\n")+CString("FileFormat:")+test+CString("\r\n");
file0.Write((LPCTSTR)texttest,texttest.GetLength()+1);
//////////////////////////////////////////////
file.Seek(10,CFile::begin);
file.Read(&data8,buchang8);
memcpy(&xtfdata.RecordingProgramVersion,&data8,buchang8);
test.Format("%s",xtfdata.RecordingProgramVersion);
texttest=CString("RecordingProgramVersion[8]:")+test+CString("\r\n");
file0.Write((LPCTSTR)texttest,texttest.GetLength()+1);
/////////////////////////////////////////////
////////////////////////////WORD SonarType
file.Seek(34,CFile::begin);
file.Read(&data2,buchang2);
memcpy(&xtfdata.SonarType,&data2,buchang2);
test.Format("%u",xtfdata.SonarType);
texttest=CString("SonarType:")+test+CString("\r\n");
file0.Write((LPCTSTR)texttest,texttest.GetLength()+1);
//////////////////////////long NavigationLatency
file.Seek(204,CFile::begin);
file.Read(&data4,buchang4);
memcpy(&xtfdata.NavigationLatency,&data4,buchang4);
test.Format("%lu",xtfdata.NavigationLatency);
texttest=CString("NavigationLatency:")+test+CString("\r\n");
file0.Write((LPCTSTR)texttest,texttest.GetLength()+1);
///////////////////////////////
这样使用多次,甚至上千次(就是读取一个格式的结构,按照字节读),发现读取到一定阶段后出现DEBUG中断,始终不知道是什么错误,前几天还运行正常,几天没变程序,歇了几天再打开出现不能运行,有事还会出现内存不足的情况,希望大侠指点!
[解决办法]
把所有变量初始化为{0}, char xtfdata.RecordingProgramVersion[9];多出一个。