我創建了一個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標誌着這個位置,這個投影只會阻止編譯器告訴你做錯了什麼。它並沒有阻止你做錯事。堆腐敗是結果。 –