u013837566
viviayi
2016-05-22 08:34

MFC程序内存泄漏,定位是求逆的函数,不知道怎么改

新手小白,MFC程序内存泄漏,用____CrtSetBreakAlloc()定位发现是一个矩阵求逆的函数,不知道怎么改,下面是求逆函数___
void inv(float a[4][4], float b[4][4]) //矩阵求逆
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
b[i][j] = a[i][j];
}
}
//int *is, *js, i, j, k;
int n = 4;
double d, p;
int *is = new int[n];
int *js = new int[n];
int i, j, k;
for (k = 0; k {
d = 0.0;
for (i = k; i for (j = k; j {
p = fabs(b[i][j]);
if (p>d){ d = p; is[k] = i; js[k] = j; }
}
if (d + 1.0 == 1.0)
{
delete[] is, js;
exit(1);
}
if (is[k] != k) //全选主元
for (j = 0; j {
p = b[k][j]; b[k][j] = b[is[k]][j]; b[is[k]][j] = p;
}
if (js[k] != k)
for (i = 0; i {
p = b[i][k]; b[i][k] = b[i][js[k]]; b[i][js[k]] = p;
}
b[k][k] = 1.0 / b[k][k];
for (j = 0; j if (j != k) b[k][j] = b[k][j] * b[k][k];
for (i = 0; i if (i != k)
for (j = 0; j if (j != k) b[i][j] = b[i][j] - b[i][k] * b[k][j];
for (i = 0; i if (i != k) b[i][k] = -b[i][k] * b[k][k];
}
for (k = n - 1; k >= 0; k--)
{
if (js[k] != k)
for (j = 0; j<n; j++)
{
p = b[k][j]; b[k][j] = b[js[k]][j]; b[js[k]][j] = p;
}
if (is[k] != k)
for (i = 0; i<n; i++)
{
p = b[i][k]; b[i][k] = b[i][is[k]]; b[i][is[k]] = p;
}
}
delete[] is, js;
}
图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答

为你推荐