【发布时间】: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