在运行时,delete noStimu这个变量时还没问题,但一delete Stimu这个变量时就出现Windows已在***.exe中触发一个断点,其原因可能是堆被损坏。
若是把代码
for(int i=0;i<90;i++)
{
delete [] Stimu[i];
}
delete [] Stimu;
注释掉;则循环调用这个函数时,在第二次delete noStimu时会出现***.exe中的0x1031e2c(msvcr100d.dll)处有未经处理的异常:0xC0000005 :读取位置0xfeeefee8时发生访问冲突。
实在是不知道怎么回事了,希望有人帮忙解答的
int count1 = 0;
int count2 = 0;
double **noStimu;
double **Stimu;
noStimu=new double *[90];//存储非刺激的90次trial
for(int i=0;i<90;i++)
{
noStimu[i] = new double [18];
}
Stimu=new double *[90];//存储非刺激的90次trial
for(int i=0;i<90;i++)
{
Stimu[i] = new double [18];
}
for (int i = 0; i < _trial; i++)
{
if (card[i] == 0 || card[i] == 1)
{
for (int j = 0; j < 18; j++)
{
noStimu[count1, j] = allVectors[i, j];//存放非刺激的特征向量,90
}
count1++;
}
else
{
for (int j = 0; j < 18; j++)
{
Stimu[count2, j] = allVectors[ i, j];//存放刺激的特征向量,90
}
count2++;
}
}
int testnum = _trial / 20;//9
int i=0;
int j=0;
srand( (unsigned)time( NULL ) );
int rdtemp = 0;
bool isIn = false;
int* rdn = new int[testnum]();//9
rdn[0] = rand()%(_trial / 2 - 1);//0-89
for (int p = 1; p < testnum; p++)
{
rdtemp = rand()%(_trial / 2 - 1);//0-89
while (1)
{
i=0;
while (i<testnum)
{
if (rdn[i]==rdtemp)
{
break;
}
i++;
}
if (i==testnum)
{
rdn[p]=rdtemp;
break;
}
else
{
rdtemp = rand()%(_trial / 2 - 1);
}
}
}
int* rdn2 = new int[testnum];
rdn2[0] = rand()%(_trial / 2 - 1);
for (int p = 1; p < testnum; p++)
{
rdtemp = rand()%(_trial / 2 - 1);
while (1)
{
j=0;
while (j<testnum)
{
if (rdn2[j]==rdtemp)
{
break;
}
j++;
}
if (j==testnum)
{
rdn2[p]=rdtemp;
break;
}
else
{
rdtemp = rand()%(_trial / 2 - 1);
}
}
}
int c1 = 0;
int c2 = 0;
int c1_1 = 0;
int c2_1 = 0;
for (int i = 0; i < _trial / 2; i++)
{
isIn = false;
int n = 0;
if (c1 < testnum)
{
while (n < testnum)
{
while(i == rdn[n])
{
for (int j = 0; j < 18; j++)
{
noStimu_tes[c1, j] = noStimu[i, j];
}
isIn = true;
c1++;
break;
}
n++;
}
}//根据随机数挑出9个非刺激向量
if (!isIn)
{
if (c2 < _trial / 2 / 10 * 9)
for (int j = 0; j < 18; j++)
{
noStimu_tri[c2, j] = noStimu[i, j];//81个非刺激向量
}
c2++;
}
n = 0;
isIn = false;
if (c1_1 < testnum)
{
while (n < testnum)
{
while(i == rdn2[n])
{
for (int j = 0; j < 18; j++)
{
Stimu_tes[c1_1, j] = Stimu[i, j];//根据随机数挑出9个刺激向量
}
c1_1++;
isIn = true;
break;
}
n++;
}
}
if (!isIn)
{
if (c2_1 < _trial / 2 / 10 * 9)
for (int j = 0; j < 18; j++)
{
Stimu_tri[c2_1, j] = Stimu[i, j];//81个刺激向量
}
c2_1++;
}
}
for(int i=0;i<90;i++)
{
delete [] noStimu[i];
}
delete [] noStimu;
for(int i=0;i<90;i++)
{
delete [] Stimu[i];
}
delete [] Stimu;
delete []rdn;
delete []rdn2;