[問題] 出現 cause 'memory not mapped'
因為我拿我在Windows上的c code(可執行) 丟到 Linux 上執行不動
然後用 valgrind 檢查過, 發現似乎沒有把記憶體釋放乾淨?!
HEAP SUMMARY:
in use at exit: 39,073 bytes in 656 blocks
total heap usage: 734 allocs, 78 frees, 52,671 bytes allocated
最後valgrind 說出現有一個error(沒說哪一行) 但我目前沒有找到很明顯的錯誤.
下面是我的部分code, 請大家幫幫忙, 找了好久看不到 感謝
-----
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void coord8(double *X, double *XX,double *y, double *lambda, double *eps, int
*ncolX, int *n, double *beta_hat, double *err,int *iter)
{
int i,j,k,v;
double nRow = *n;
double nCol = *ncolX;
double lam = *lambda;
double *x_squared, *xy, *partial_residual_sum, *beta_temp, b, temp,
tempxy,temp_sum, t1, t0;
double **x = (double **)calloc(nRow ,sizeof(double*));
double **xx = (double **)calloc(nCol,sizeof(double*));
for(i = 0; i < nRow; ++i)
x[i] = (double *)calloc(nCol, sizeof(double));
for(i = 0; i < nCol; ++i)
xx[i] = (double *)calloc(nCol, sizeof(double));
x_squared =(double*) calloc(nCol,sizeof(double));
partial_residual_sum =(double*) calloc(nCol,sizeof(double));
beta_temp =(double*) calloc(nCol,sizeof(double));
xy =(double*) calloc(nCol,sizeof(double));
中間是一些代數運算
for(i = 0; i < nRow; i++)
free(x[i]);
free(x);
for(i = 0; i < nCol; i++)
free(xx[i]);
free(xx);
free(x_squared);
free(xy);
free(partial_residual_sum);
free(beta_temp);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.114.59
※ 編輯: JimCroce 來自: 140.113.114.59 (03/16 11:48)
→
03/16 13:31, , 1F
03/16 13:31, 1F
→
03/16 13:32, , 2F
03/16 13:32, 2F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章