473,322 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

CALLOC: very extrange problem

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
6 2278
horace1
1,510 Expert 1GB
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
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
horace1
1,510 Expert 1GB
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
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
horace1
1,510 Expert 1GB
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
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

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

Similar topics

26
by: dagger | last post by:
Hi there. I'm using C under FreeBSD with the gcc compiler and am having a bit of trouble using the calloc and realloc calls. As an example the code snippet: #include <stdio.h> int main() {...
16
by: laberth | last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why? Here is what I use : typedef struct noeud { int val; struct noeud *fgauche; struct noeud *fdroit; } *arbre; //for those...
14
by: Rahul Gandhi | last post by:
Which one is more fast? malloc followed by memset or calloc
27
by: MK | last post by:
I am a newbie. Please help. The following warning is issued by gcc-3.2.2 compiler (pc Linux): ================================================================== read_raw_data.c:51: warning:...
40
by: boris | last post by:
Hi! I'm seeking some answers about what seems to be a memory leak. I have a loop that looks much like this: double *largeArray = (double*) calloc(); for (...) { printf("iteration #...\n");...
11
by: lohith.matad | last post by:
Hi all, Though the purpose of both malloc() and calloc() is the same, and as we also know that calloc() initializes the alloacted locations to 'zero', and also that malloc() is used for bytes...
2
by: chingfulan | last post by:
I have the following code and I can not figure out why Stg2In returns a null pointer? "Stg2In = (float *)calloc(9*DataLen, sizeof(float)); " while "Stg2Out = (float *)calloc(9*DataLen,...
7
by: mef526 | last post by:
I have had this problem for months now and it has been nagging me. I have a large project that has several C++ DLL's, one of them uses malloc / calloc / free for the other DLL's. I process very...
1
by: gallerto | last post by:
I have a very extrange problem with calloc. I am working with Dev-C++ in Windows. Another extrange thing is that when I try to run the debugger it does not run. Only with the firstt file. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.