memset()对数组做了什么?
今天调试程序,在new一个数组后,用memset对其进行置0,而后delete之,居然出现了“CRT detected that the application wrote to memory after end of heap buffer”的故障。代码如下:
char *recordAllD = new char[amountdata]; //amountdata 为文件中数据量
CString *readedAll = new CString [(amountdata + 1) / 7];
memset(recordAllD, 0, sizeof(recordAllD));
readedRecord.Read(recordAllD, readedRecord.GetLength()); //这是CFile对象,用以获得值
for (int i=0; i<(amountdata+1)/7; i++)
{
for (int j=0; j<6; j++)
{
readedAll[i] = readedAll[i] + recordAllD[i*7+j];
}
}
delete[] recordAllD;
认真分析,发现:当amountdata为0时,出现故障,当amountdata为0时,将其强制赋值为4时,故障排除,即便为3也会出现该故障;而将memset屏蔽掉后也能排除该故障。这是什么原因,难道memset改变了数组的长度??在MSDN中查找,上面没有对其的说明。思考中,烦请各位大侠赐教!!