Data loss during run time.

Hi, I was debugging my C++ program, because I find some errors in the result of the same, and discovered that during run time the program delete the content of at least one of my variables. In this case a matrix.

When mounting the matrix I call some functions to read files and write in the matrix according to the position. At some point during run time I call another function and then the value of the matrix goes to zero or some trash and another variables start to losing data.

Anyone known how to mitigate this?
Last edited on
It would really help the helpers to see any snippets of your code that is relevant to this error.
also remember to use [code] format so the helping hands can easily read the code.
Indeed without showing some code noone would be able to help you
Ok. Here's a piece of code. The program has

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
create_A_matrix (){
       A_matrix = new double [a*a];
       create_g();// calculate some elements that enter in the matrix
       create_so(); //  the same
       for (int i=0; i<a; i++){
              for (int j=0; j<a; j++){
              .
              .// put the elements in the matrix with some logic.
       }}; // so far the A matrix it's ok
} ;
i_vector(); // matrix is ok.
b_vector (){ //when I call this function occur the data loss I don't even manipulate the same numbers. 
        for (int i=0; i<a; i++){
        .
        .
} 

it's like the compiler limits the amount of memory and from that point on it start the data loss. I don't known if it's the compiler or something else
Last edited on
I am unsure, it sounds like an issue with code scope and not an issue with the compiler. And post a little more. Like, when did you call b_vector ? Is b_vector non-void? does b_vector take any parameters? What is going on in the for loops because my brain is complaining about the periods '.'.
You are using an array for your matrix which makes it a bit hard to use const to ensure no change would appear in your matrix.

Anyway, what exactly is your function b_vector () do?
And what do you mean by
I don't even manipulate the same numbers
?

Have you considered using some other container for your matrix? Like vector for example?

Edit: P.S.

P.S. I don't want to disappoint you but the possibility of compiler bug is really unlike (not impossible) just really unlikely to occur. Consider that a compiler is something millions face with while your code is not. So consider the possiblity of an error such as this that it will go unnoticed?
Last edited on
The program at this point its preparing to solve the linear system Ax=b. So I'm mounting the A matrix and the b vector, to prepare for a LU decomposition and a the solve. I'm using the LU decomposition because I have to solve the linear system multiples times.

.What is going on in the for loops because my brain is complaining about the periods '.'.

Inside the for loop in the matrix A I start to fill the A matrix with the data that's already stored in the memory. According to the conditions.
it's like this
1
2
3
4
5
if (i==j) {
      A_matrix[i*a +j]= gaii;
} else {
      A_matrix[i*a +j]= gaij; // its a little more elaborated than this but this is the idea.
}; // It's the same with the b_vector;  



Anyway, what exactly is your function b_vector () do? And what do you mean by I don't even manipulate the same numbers?


I mean that I manipulate a different sort of data.
Without a more detailed print out of your code of where you believe the problem is happening, we will not be able to find where the bug might be in your code. Right now I still do not see what the problem is that you are having, and some of the questions from the other members prove that they do not see your problem yet either. Help us to help you :)
Topic archived. No new replies allowed.