debugging a memory violation problem

Discussion in 'C++' started by pauldepstein@att.net, Jan 14, 2006.

  1. Guest

    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
    , Jan 14, 2006
    #1
    1. Advertising

  2. TB Guest

    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.
    >
    >>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.
    >


    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
    TB, Jan 14, 2006
    #2
    1. Advertising

  3. Daniel T. Guest

    In article <>,
    wrote:

    > 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?


    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




    --
    Magic depends on tradition and belief. It does not welcome observation,
    nor does it profit by experiment. On the other hand, science is based
    on experience; it is open to correction by observation and experiment.
    Daniel T., Jan 15, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kyle Teague
    Replies:
    3
    Views:
    654
    David White
    Nov 26, 2003
  2. Bengt Richter

    time.mktime memory access violation bug

    Bengt Richter, Nov 18, 2003, in forum: Python
    Replies:
    6
    Views:
    682
    Bengt Richter
    Nov 21, 2003
  3. Bit byte

    Memory (read) access violation handling in C

    Bit byte, Jun 18, 2006, in forum: C Programming
    Replies:
    4
    Views:
    605
    Dave Thompson
    Jun 26, 2006
  4. aling
    Replies:
    12
    Views:
    552
    Greg Comeau
    Nov 15, 2005
  5. Replies:
    3
    Views:
    1,097
Loading...

Share This Page