删除矩阵时的访问冲突写入位置
Access violation writing location when deleting a matrix
我正在写一个程序来执行一组数值方法。要做到这一点,我需要创建任意大小的矩阵,并将它们放在函数之间。显然,如果我在使用create矩阵后不清理它们,我就会得到相当严重的内存泄漏。
double** MatrixInitialize(int m, int n)//generates a A[m][n] matrix
{
int i = 0, j = 0;
double** B = new double*[m];
for (m = 0; m < n; m++)
{
B[m] = new double[n];
}
for (j = 0;j<m;j++)
for (i = 0; i < n; i++)
{
B[i][j] = 0;
}
return(B);
}
int main()
{
double** MatrixA;
MatrixA=MatrixInitialize(2,2)
//Some manipulation on MatrixA is done here
delete[] MatrixA[0]; delete[] MatrixA[1]; delete[] MatrixA;
return 0;
}
一旦调用delete[]行,就会抛出访问冲突消息,必须中断。删除这些指针还有其他的步骤吗?
让语言为你工作
int main()
{
int ysize = 10;
int xsize = 5;
std::vector<std::vector<double>> B(ysize, std::vector<double>(xsize, 0));
for (int y = 0; y < ysize; y++)
{
for (int x = 0; x < xsize; x++)
{
B[y][x] = 1.23;
}
}
for (int y = 0; y < ysize; y++)
{
for (int x = 0; x < xsize; x++)
{
std::cout << B[y][x] << " ";
}
}
std::cout << "n";
}
http://ideone.com/QSoR5M 相关文章:
- 写入位置0x0000000C时发生访问冲突
- 0xC0000005:访问冲突写入位置0xCDCDCDCD动态分配错误
- 0xC0000005:访问冲突读取位置 0x00000000. 重载 == 运算符的问题
- (此函数用于计算 SMA).在 FA.exe 中0x00509159引发异常: 0xC0000005:访问冲突读取位置0
- 0xC0000005:读取位置0xCDCDCDC1时发生访问冲突
- 0xC0000005:读取位置0xCDCDCDCD时发生访问冲突
- 读取类的析构函数中的位置时发生访问冲突
- 在尝试使用CUDA分配内存时,我遇到了访问冲突写入位置错误
- 创建 2D 数组0xCCCCCCCC访问冲突写入位置
- 0x0F50DF58:0xC0000005:访问冲突读取位置0x0047CA04时未处理的异常
- 在 DLL 中嵌入 Python:Py_DECREF列表对象时访问冲突读取位置
- 在 C 代码中调用 Python 函数时第三次出现访问冲突写入位置错误
- 0xC0000005:访问冲突读取位置0x0000000000000008
- 使用动态数组访问冲突写入位置
- C++访问冲突读取位置0xDDDDDDCD当我尝试删除已更新的数组时
- 使用向量的函数崩溃,调试器说访问冲突读取位置
- vc++ 访问冲突读取位置
- C++ - 智能指针 - 访问冲突读取位置0xDDDDDDDD
- C++访问冲突读取位置错误
- 调用隔离后访问冲突执行位置0x0000000000000000:New()