By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,848 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

CALLOC: very extrange problem

P: 11
I have a very extrange problem with calloc.

I am working with Dev-C++ in Windows. The code is in C but I compile it as C++. All my files are .cpp

I will explain the situation. I have a program that calculates forces using data files. Each data file corresponds to experimental measures in an instant and from each file you can get the force in this instant.

The program is used to calculate the forces in a lot of instants. Each data file has exactly de same number of doubles ordered in exactly the same way. To solve each file the program does always exactly the same. It is just a loop that reads the files and solves them one after the other.

I found that when I tell the program to calculate the force in the files from 50 to 350 it stops unexpectedly in the file 75. I tryed to run the program to solve the forces between files 51 to 351 and I expected that it stops in file 75 or 76. But it stops in file 253. It means that the file 75 is not corrupted and that it is not a problem of memory that appears after solving a number exact of files.

The file where the error happens depends only on the file where you start to solve the forces. It is always the same. It shows that it is not random. However each file is read and deleted after it is used so it is extrange that the error deppends on the data file where you start the execution.

I looked for the error and it happens in exactly this line of code:

aux=(double *) calloc(lN-l1+1,sizeof(double));

Where lN-l1+1 = 2. This line of code is exectuted exactly with the same arguments for each data file however it fails only with some files.

calloc does not return a null ponter. The program stops when it arrives to this line so you don't have a null pointer. You have nothing.

I checked with the tasks administrator of windows that I have more than enough memory.

Another extrange thing is that when I try to run the debugger it does not run. Only with the first data file, but it stops after that I don't know still exactly in what line.

If I execute the program in a different computer the program stops in a different moment. I still didn't check but probably in a similar line.

The program stops in a different moment when I execute it cliking over the "compile and execute" button of the Dev-C++ environment or when I execute it writing the name of the program in the MSDOS command window.

The results that the program gives while it works are good, even with that files where it stops when you star to solve with certain files.

These are all the things I have tested. I hope somebody can help me. I don't know what else I can try.


Thank you very much
Mar 16 '07 #1
Share this Question
Share on Google+
6 Replies


Expert 100+
P: 1,510
after reading a file do you close it or leave it open - if you don't close it it could be a problem with the maximum number of files that can be open at any one time. When the program fails does it give a segmentation error or just freeze? Can you still run other programs ?
Mar 16 '07 #2

P: 11
after reading a file do you close it or leave it open - if you don't close it it could be a problem with the maximum number of files that can be open at any one time. When the program fails does it give a segmentation error or just freeze? Can you still run other programs ?
Yes I close them. But I have a file oppened all the time where I store the results.

But I don't think that it is the reason beause deppending on the file where I star I can solve 26 or 200 hundred files.

When the program fails it deppends on the computer (all of them windows) and on the file where I start:

CASE 1: in one of them I get the typical window where they ask me if I want to send an error report.

When I say I don't want to send the report the typical little MSDOS window doesn't close for some seconds. I can't "compile and execute" again untill it closes but the other programs work without any problem.

If I try to close the window cliking over the x on the upper left corner I get the typical window telling me that windows can't close the program, that maybe more time is needed

In other computer the program just stops, the MSDOS window closes and it is how if I hadn't executed the program.

CASE 2: in some conditions, I don't know exactly wich ones (i can't reproduce it now) in both computers when the program fails and I try to "compile and execute" again the DevC++ does not execute because it says: "permission denied"

Thank you
Mar 16 '07 #3

Expert 100+
P: 1,510
could you be running out of virtual memory?

does the number of other programs you are running at the time effect how your program runs?

which version of windows are you running?
Mar 16 '07 #4

P: 11
could you be running out of virtual memory?

does the number of other programs you are running at the time effect how your program runs?

which version of windows are you running?
I can see with the tasks administrator of windows XP that i have a lot of RAM memory.

The program needs around 15-30 MB to run.

No, the number of programs does not affect.
Mar 16 '07 #5

Expert 100+
P: 1,510
I can see with the tasks administrator of windows XP that i have a lot of RAM memory.

The program needs around 15-30 MB to run.

No, the number of programs does not affect.
have you tried running it from the command prompt rather than from DEV-C++?
Mar 16 '07 #6

P: 11
have you tried running it from the command prompt rather than from DEV-C++?
Yes I did, And as I have allready told the behaviour is different.

Thank you
Mar 16 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.