why engOpen fails with memory error when run more times my function in MS VS 2010 c/c++ ?

3 views (last 30 days)
Hi, i study matlab engine for c /c++ programing language. i have a function that retuns eigenvectors. when i run my code it runs successfully in first time but in second run gives error with memory ? i want to run the program(main) ones but call this function in main program more times.But it gives error in engOpen command?i dont know why it gives this error?Please help !
my function is this :
double** ozvektor_dondur_double(int **dizi,int satir,int sutun,int satir_donen,int sutun_donen) { Engine *ep; mxArray *mp; double *ar; mxArray *T = NULL, *V_sirali = NULL, *D_Sirali = NULL; int i,j,c; //mxCreateDoubleMatrix(satir sayisi,sutun sayisi,mxREAL); mp = mxCreateDoubleMatrix(satir,sutun,mxREAL); //memcpy((void *)mxGetPr(mp), (void *)time, sizeof(time));//mp ye yer ayrılıyor... //int satir,sutun; //satir=3; //sutun=3; //mp dizisine değer atıyorum. ar = mxGetPr(mp); for( i =0;i<satir;i++) { for (j = 0;j<sutun;j++) { ar[i+j*satir] = dizi[i][j]; } } bool vis; //matlab engine başlatılıyor... //ep = engOpen(""); //ep=engOpen(NULL); if (!(ep = engOpen("\0"))) { fprintf(stderr,"\nCan't start MATLAB engine"); exit(-1); }
engGetVisible(ep, &vis); if(vis) engSetVisible(ep, 0); engPutVariable(ep,"data",mp); engEvalString(ep,"alpha=double(data);"); engEvalString(ep,"[V, D] = eig(alpha);"); engEvalString(ep,"[DSirali order] = sort(diag(D),'descend');"); engEvalString(ep,"VSirali = V(:,order);"); V_sirali = engGetVariable(ep,"VSirali"); D_Sirali = engGetVariable(ep,"DSirali"); //-------------------------------------- double *sonuc; sonuc=D2_dizi_yerac_double(satir_donen,sutun_donen); double *real_data_ptr; real_data_ptr = (double *)mxGetPr(V_sirali); / Giriş dizisinin gerçek elemanlarının başlangıç adresini verir */ for (i= 0; i < satir_donen; i++) for (j= 0; j < sutun_donen; j++) sonuc[j][i]=*real_data_ptr++; yazdir(V_sirali); engClose(ep);//matlab engine kapatılıyor... mxDestroyArray(mp); mxDestroyArray(T); mxDestroyArray(V_sirali); mxDestroyArray(D_Sirali); return sonuc;
}
error is this:
  1 Comment
Geoff Hayes
Geoff Hayes on 20 Aug 2014
Fike - please attach the function ozvektor_dondur_double to your question using the paperclip button. The C++ code is difficult to decipher when it appears as it does in the above question.

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!