我创建了一个C++ DLL函数,它使用几个数组来处理最终的图像数据。我试图通过引用传递这些数组,并进行计算,并在预分配数组中通过引用传回输出。在功能我用的是英特尔性能原件,包括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)
这会导致我的问题:这是内存泄漏吗?如果是这样,任何人都可以看到泄漏位置?如果没有,有人可以建议如何去调试这个问题?
内存泄漏不会产生访问冲突。如果有的话,你似乎有相反的问题。 –
内存泄漏与访问冲突几乎相反。 – Nawaz
此代码不可读。但是X标志着这个位置,这个投影只会阻止编译器告诉你做错了什么。它并没有阻止你做错事。堆腐败是结果。 –