【问题标题】:I *think* I have a memory leak. What now?我*认为*我有内存泄漏。现在怎么办?
【发布时间】:2011-09-27 15:56:30
【问题描述】:

我创建了一个 C++ DLL 函数,它使用多个数组来处理最终的图像数据。我试图通过引用传递这些数组,进行计算,并在预分配的数组中通过引用将输出传回。在函数中,我使用 Intel Performance Primitives,包括 ippsMalloc 和 ippsFree:

Process.dll

int __stdcall ProcessImage(const float *Ref, const float *Source, float *Dest, const float *x, const float *xi, const int row, const int col, const int DFTlen, const int IMGlen)
{
int k, l;
IppStatus status;
IppsDFTSpec_R_32f *spec;
Ipp32f *y = ippsMalloc_32f(row),
    *yi = ippsMalloc_32f(DFTlen),
    *X = ippsMalloc_32f(DFTlen),
    *R = ippsMalloc_32f(DFTlen);

for (int i = 0; i < col; i++)
{
    for (int j = 0; j < row; j++)
        y[j] = Source[j + (row * i)];
    status = ippsSub_32f_I(Ref, y, row);

            // Some interpolation calculations calculations here

    status = ippsDFTInitAlloc_R_32f(&spec, DFTlen, IPP_FFT_DIV_INV_BY_N, ippAlgHintNone);
    status = ippsDFTFwd_RToCCS_32f(yi, X, spec, NULL);
    status = ippsMagnitude_32fc( (Ipp32fc*)X, R, DFTlen);

    for (int m = 0; m < IMGlen; m++)
        Dest[m + (IMGlen * i)] = 10 * log10(R[m]);
}
_CrtDumpMemoryLeaks();

ippsDFTFree_R_32f(spec);
ippsFree(y);
ippsFree(yi);
ippsFree(X);
ippsFree(R);
return(status);
}

函数调用如下所示:

for (int i = 0; i < Frames; i++)
    ProcessFrame(&ref[i * FrameSize], &source[i * FrameSize], &dest[i * FrameSize], mX, mXi, NumPixels, Alines, DFTLength, IMGLength);

该函数不会失败,并为最多 6 张图像产生所需的输出,不止于此,它会因以下原因而死:

First-chance exception at 0x022930e0 in DLL_test.exe: 0xC0000005: Access violation reading location 0x1cdda000.

我试图调试程序,不幸的是 VS 报告调用堆栈位置在 IPP DLL 中,并且“无可用源”。调用ippMagnitude32fc( (Ipp32fc*)X, R, DFTlen)时总是失败

这引出了我的问题:这是内存泄漏吗?如果是这样,任何人都可以看到泄漏的位置吗?如果没有,有人可以建议如何调试这个问题吗?

【问题讨论】:

  • 内存泄漏不会产生访问冲突。如果有的话,你似乎有相反的问题。
  • 内存泄漏几乎与访问冲突相反。
  • 此代码不可读。但是 X 标记了那个地方,那个演员只会阻止编译器告诉你做错了什么。它并没有阻止你做错事。结果是堆损坏。

标签: c++ visual-studio-2010 memory-management dll


【解决方案1】:

要回答您的第一个问题,不,这不是内存泄漏,而是内存损坏。 内存泄漏是指您没有释放已使用的内存,因此内存使用量正在增加。这不会使程序无法运行,但最终只会使用过多的内存,这会导致计算机速度非常慢(交换),并最终导致任何程序因“内存不足错误”而崩溃。 你所拥有的是基本的指针错误,因为它在 C++ 中一直发生。 解释一下怎么调试比较难,建议你在crash前加个断点,试试看是什么问题。

【讨论】:

    猜你喜欢
    • 2014-12-10
    • 1970-01-01
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 2014-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多