debugging a memory violation problem

P

pauldepstein

I have probably "bitten off more than I can chew". But, I'm new to c++
and am trying to debug a program consisting of 9 files and about 2000
lines of code.

My program compiles but I get a runtime error: "Access violation:
segmentation fault raised in your program" -- dev c++ compiler.

Here is the most specific indicator of what is going wrong: There
follows a small sample of code.
From the screen displays, I see that node_number is at 10 (the value I
want) but that k is only displayed for its first two values of 0 and 1.

The functions set_equity and set_probability are fairly complex
recursive functions.

Can anyone speculate as to where the problem might lie? Does this
sound like a problem with a destructor?

Of course, I could provide more code but the full program is too long
to be appropriate so I don't know what else to include.



node_array = new node* [node_number];

for (int k = 0; k < node_number; k++)

{ cout << endl << node_number << node_number << node_number;
cout << endl << k << k << k << k;
debug << endl << "index " << k;

node_array[k] =
new node
(params, x_coord(params, k), y_coord(params, k),
rights_coord(params, k));

node_array[k]-> set_equity();
node_array[k]-> set_probability();

// more code



Thank you,

Paul Epstein
 
T

TB

(e-mail address removed) sade:
I have probably "bitten off more than I can chew". But, I'm new to c++
and am trying to debug a program consisting of 9 files and about 2000
lines of code.

My program compiles but I get a runtime error: "Access violation:
segmentation fault raised in your program" -- dev c++ compiler.

Use the debugger with breakpoints and step through the code until
it happens.
Here is the most specific indicator of what is going wrong: There
follows a small sample of code.

want) but that k is only displayed for its first two values of 0 and 1.

Then most likely the error occurs in code executed after '1' is printed.
The functions set_equity and set_probability are fairly complex
recursive functions.

That shouldn't stop you from diving right in and debug them.
Can anyone speculate as to where the problem might lie? Does this
sound like a problem with a destructor?

Which destructor?
Of course, I could provide more code but the full program is too long
to be appropriate so I don't know what else to include.



node_array = new node* [node_number];

for (int k = 0; k < node_number; k++)

{ cout << endl << node_number << node_number << node_number;
cout << endl << k << k << k << k;
debug << endl << "index " << k;

node_array[k] =
new node
(params, x_coord(params, k), y_coord(params, k),
rights_coord(params, k));

node_array[k]-> set_equity();
node_array[k]-> set_probability();

So these two member functions should be your primary target, concidering
how little code who posted. And the functions 'x_coord' and 'y_coord',
as well as the constructor of 'node'. Trace and isolate the problem. We
cannot speculate and guess what your code looks like to find a problem.

TB
 
D

Daniel T.

I have probably "bitten off more than I can chew". But, I'm new to c++
and am trying to debug a program consisting of 9 files and about 2000
lines of code.

My program compiles but I get a runtime error: "Access violation:
segmentation fault raised in your program" -- dev c++ compiler.

Here is the most specific indicator of what is going wrong: There
follows a small sample of code.

want) but that k is only displayed for its first two values of 0 and 1.

The functions set_equity and set_probability are fairly complex
recursive functions.

Can anyone speculate as to where the problem might lie? Does this
sound like a problem with a destructor?

I don't see how this could be a destructor problem since no destructor
is called from within this code segment (if one is, then the code
calling it is at error.)
Of course, I could provide more code but the full program is too long
to be appropriate so I don't know what else to include.

One of the functions called in this code is accessing invalid memory.
Your going to have to step into the offending function until you find
the problem.
node_array = new node* [node_number];

for (int k = 0; k < node_number; k++)

{ cout << endl << node_number << node_number << node_number;
cout << endl << k << k << k << k;
debug << endl << "index " << k;

node_array[k] =
new node
(params, x_coord(params, k), y_coord(params, k),
rights_coord(params, k));

node_array[k]-> set_equity();
node_array[k]-> set_probability();

// more code



Thank you,

Paul Epstein
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top