2011-09-27 39 views
1

我創建了一個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)

這會導致我的問題:這是內存泄漏嗎?如果是這樣,任何人都可以看到泄漏位置?如果沒有,有人可以建議如何去調試這個問題?

+3

內存泄漏不會產生訪問衝突。如果有的話,你似乎有相反的問題。 –

+0

內存泄漏與訪問衝突幾乎相反。 – Nawaz

+0

此代碼不可讀。但是X標誌着這個位置,這個投影只會阻止編譯器告訴你做錯了什麼。它並沒有阻止你做錯事。堆腐敗是結果。 –

回答

2

要回答你的第一個問題,沒有那不是內存泄漏,這是內存損壞。 內存泄漏是在您沒有釋放使用的內存時發生的,因此內存使用量正在增長。這並不會導致程序無法正常工作,但最終只會使用太多的內存,導致計算機非常慢(交換),並最終導致任何程序因'內存不足錯誤'而崩潰。 你有什麼是基本的指針錯誤,因爲它總是在C++中發生。 解釋如何調試很困難,我建議你在崩潰前添加一個斷點,並嘗試查看出了什麼問題。