高手帮忙进来看看代码!急用
调用InitSmpData()函数会出现严重问题
1.ReadConvertData()函数有内存泄露(i>394时候)
2.InitSmpData()函数调用,在mySDList.AddTail(pCSmpData)这一句,
会Debug Assertion Failed,然后要求终止程序
代码如下:
double* CMyDoc::ReadConvertData()
{
CFile tfile;
char* pFileName = "2005年12月15日22时34分32秒.dat";
if(tfile.Open(pFileName,CFile::modeRead))
{
WORD word;
double* pVData = new double[1024];//digital
tfile.Seek(60,CFile::begin);//
for(int i=0;i<1024;i++)//i>394会检测到内存泄露
{
pVData[i] = 0.0;
tfile.Read(&word,2);
word = word>>4;
if(word >= 2048)
pVData[i] = (-1)*(4096-word)*10.0/4096;
else
pVData[i] = word*10.0/4096;
TRACE("pVData[%d]=%f\n",i,pVData[i]);
}
tfile.Close();
return pVData;
}
else
{
CWnd* pwnd;
pwnd->MessageBox("File Open Failed!","ERROR",MB_OK|MB_ICONWARNING);
return NULL;
}
}
void CMyDoc::InitSmpData()
{
double* pData = new double[1024];
pData = ReadConvertData();
if(pData !=NULL)
{
for(int i = 0;i<1024;i++)
{
CSmpData* pCSmpData = new CSmpData(pData[i],i/SplRate_ext);
mySDList.AddTail(pCSmpData);//调试到这句,会Debug Assertion Failed
} //应该没问题的阿,问题在哪呢???
}
delete[] pData;
TRACE("in the Fuction:IniSmpData()");
}