c++ - C++中的堆损坏

标签 c++ heap-memory heap-corruption

当我在 Visual C++ 2010 中运行我的代码时,我在运行时遇到错误。

void dct2(){
    float** G = new float*[len];
    for(int u = 0; u < len; u++){
        G[u] = new float[len];
        for(int v = 0; v < len; v++){
            G[u][v] = 0;
            for(int x = 0; x < len; x++){
                for(int y = 0; y < len; y++){
                    G[u][v] += a(u) * a(v) * (float)mat[x][y] * cos((PI / 8) * u * (x + 0.5)) * cos((PI / 8) * v * (y + 0.5));
                }
            }
        }
    }
    doublecpy(G);
}
void doublecpy(float** d){
    for(int i = 0; i < len; i++){
        for(int j = 0; j < len; j++){
            if(d[i][j] >= 0)
                mat[i][j] = (int)(d[i][j] + 0.5);
            else
                mat[i][j] = (int)(d[i][j] - 0.5);
        }
    }
    for(int i = 0; i < len; i++)
        delete[] d[i];
    delete[] d;
}

错误出现在行中:delete[] d[i]; 请告诉我这段代码是否有任何问题或任何建议。

最佳答案

除了你不应该以这种方式编写 C++(这只是 C 和 new 而不是 malloc)之外,我看不到任何内存错误,但不知道 mat 是什么以及它是如何分配的。

关于c++ - C++中的堆损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5104736/

相关文章:

c++ - 用于 int3 的 Cuda AtomicAdd

c++ - 在函数之间的堆上传递数组时导致此运行时错误的原因,c++

c++ - 嵌入式 Linux 上的轻量级调试

java - 如何在没有 OutOfMemoryError 的情况下读取 1.5GB XML 文件并将其分配给字符串?

使用 free() 时 C 堆缓冲区损坏

c++ - 我收到错误 c++ assertion failure heap corruption detected

c - 如何在 Linux 上调试内存损坏

c - 在 C 中正常 block (#155) 后检测到堆损坏

c# - 使用 SWIG 从 C++ 回调到 C#

c++ - 在 C++ 中修改模拟时间