Memory allocation problem!

laojiang 7850242 at qq.com
Sat Sep 3 23:42:35 CEST 2011


Hi, I have a problem,such as I definite a one dimension array, and allocate it memory, but it did not works:
 int n0,i;
 mpf_t *f_f0;
 double *f0;
 f_f0= ( mpf_t *)malloc(n0 * sizeof( mpf_t *)); 
 f0= ( double *)malloc(n0 * sizeof( double *)); 
  for (n = 0; n < n0+1; n++) 
    {
      mpf_init(f_f0[n]);
     } 
   for(i =0;i<n0+1;i++ )
    {
      xval[i] = cos(pih *(2.0 *(i+1)-1.0)/(n0+1));
    }
   for(i =0;i<n00;i++ )
    {
       mpf_set_d(f_f0[i],f0[i]);
     } 
 When I run the code,the result is :
 jwe0019i-u The program was terminated abnormally with signal number SIGSEGV.
           signal identifier = SEGV_MAPERR, address not mapped to object
 Error occurs at __gmpf_set
And when I change the code like this:
  f_f0= ( mpf_t *)malloc(2*n0 * sizeof( mpf_t *)); 
 It can works. Could you tell me the reason? Thanks in advance!
 Cheers,
 Zhonghe Jiang


More information about the gmp-discuss mailing list