Re: segmentation fault on calloc
From: Mathieu Fregeau (mathieu.fregeau_at_polymtl.ca)
Date: 11/03/03
- Next message: Nuage: "Re: How to Remove the First Line of a File, lines containing Alphabetic characters?"
- Previous message: Alex Fedotov: "Re: normalizing Unix and Windows file datestamps"
- In reply to: Mathieu Fregeau: "segmentation fault on calloc"
- Next in thread: Måns Rullgård: "Re: segmentation fault on calloc"
- Reply: Måns Rullgård: "Re: segmentation fault on calloc"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
>
>
- Next message: Nuage: "Re: How to Remove the First Line of a File, lines containing Alphabetic characters?"
- Previous message: Alex Fedotov: "Re: normalizing Unix and Windows file datestamps"
- In reply to: Mathieu Fregeau: "segmentation fault on calloc"
- Next in thread: Måns Rullgård: "Re: segmentation fault on calloc"
- Reply: Måns Rullgård: "Re: segmentation fault on calloc"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|