Re: segmentation fault on calloc

From: Mathieu Fregeau (mathieu.fregeau_at_polymtl.ca)
Date: 11/03/03


Date: Mon, 03 Nov 2003 15:31:41 GMT

Hi,

I have "found" the problem... but I don't understand the real why. Let me
remind you my code. the original code and the "main" is in C, I am putting
my modification in Fortran. From now, no problems. But I am using a F90
features that, yes, allocates dynamic memory, on the heap, to some 2
dimensions arrays. And probably because the function to allocates memory is
within the language and did not use the same logic to delegates memory,
there was a conflict at run time and not at built time. So I am going back
in time and uses F77 limitation, that is to allocates static and large
arrays to all my arrays and I increase the stack memory on built.

never use ALLOCATE (and ALLOCATABLE) in Fortran when you use the heap on a
mixed C language. (what an advice!) Mixed language will always be a pain in
the a**

Thank for all your help. I mean it.

Mathieu

"Mathieu Fregeau" <mathieu.fregeau@polymtl.ca> wrote in message
news:h5Uob.1575$Ng3.451@charlie.risq.qc.ca...
> Hi,
>
> I got a segmentation fault when using the calloc function, which purpose
is
> to avoid a segmentation fault...
>
> what is the problem?
>
> the code is (in C):
>
> int nspdim = 10000; //for the example only, the value is set at run-time
> double *apjk;
> apjk = NULL;
> apjk = (double *)calloc(nspdim,sizeof(double));
> //it crashes here, the previous line doesn't complete
> if (!apjk)
> {
> //... print a message if the calloc failed, but the program doesn't even
> goes here...
> }
>
> thanks a lot
>
> Mat
>
>



Relevant Pages

  • Re: Theodore Adorno, a prophet of data systems design
    ... > memory leaks, overruns etc., and I can even prove this without knowing ... possible to design a language in which buffer overruns are impossible. ... C makes the allocation of fixed-size arrays possible because there are some ... design and implement your own string model. ...
    (comp.programming)
  • Re: Allocatable versus automatic arrays
    ... but some of these arrays are only used conditionally.... ... it allocates a large chunk of memory ... this will make any difference in speed or memory management after the ... There can be more cost to declaring static arrays, ...
    (comp.lang.fortran)
  • Re: OOP and C++ and C (was Re: Dennis Ritchie -- An Appreciation)
    ... different layout in memory. ... A weak example is Algol 68 arrays. ... arrays (and I don't know any language that does), ...
    (comp.lang.c)
  • Re: 32 or 64 bit processor info in C
    ... For a brief momenet we have the situation where int ... You could argue that all that memory won't be used for arrays. ... merely that the language isn't going to ...
    (comp.lang.c)
  • Re: Absense of bool
    ... It abstracts variables, functions, static memory ... structures (structs and arrays) and algorithms. ... it is a language that works ... because, in ASM, arrays are represented and manipulated like that. ...
    (comp.lang.c)