strang behaviour std:vector and XString in VC6.0

Discussion in 'C++' started by Stijn Oude Brunink, Nov 12, 2004.

  1. Hello

    I'm using std:vector to hold some pointers

    vector<CBase*> x;

    In the debug version I've the following problem:
    After I've added a couple of pointers using the push_back function and I
    iterate over x the program crashes in the iteration loop. If I debug the
    program I see that the Iterator has som strange value which I did not put
    in. Finially I end up in the XString header where there seems to be some
    kind of memory allocation problem. If I ask for the last pointer in x using
    x.back() I get a good result. but x[x.size()-1] produces nonsense;

    The problem stated does not occur in release mode.

    Does anaybody know what is going on.

    I use VC6.0.

    thanks

    Stijn
     
    Stijn Oude Brunink, Nov 12, 2004
    #1
    1. Advertising

  2. Stijn Oude Brunink

    chris Guest

    Stijn Oude Brunink wrote:
    > Hello
    >
    > I'm using std:vector to hold some pointers
    >
    > vector<CBase*> x;
    >
    > In the debug version I've the following problem:
    > After I've added a couple of pointers using the push_back function and I
    > iterate over x the program crashes in the iteration loop. If I debug the
    > program I see that the Iterator has som strange value which I did not put
    > in. Finially I end up in the XString header where there seems to be some
    > kind of memory allocation problem. If I ask for the last pointer in x using
    > x.back() I get a good result. but x[x.size()-1] produces nonsense;
    >
    > The problem stated does not occur in release mode.
    >
    > Does anaybody know what is going on.
    >

    Unfortunatly, we are not able to debug your code without seeing it.

    My advise, as in all similiar cases is to try to reduce your code to an
    example of not more than 20 lines which uses no non-standard C++
    wherever possible (unless the bug appears to be being causes by
    non-standard C++). Then try posting that here or in the relevant newsgroup.

    Chris
     
    chris, Nov 12, 2004
    #2
    1. Advertising

  3. "Stijn Oude Brunink" <> wrote in message
    news:3Q1ld.1069$...
    > Hello
    >
    > I'm using std:vector to hold some pointers
    >
    > vector<CBase*> x;
    >
    > In the debug version I've the following problem:
    > After I've added a couple of pointers using the push_back function and I
    > iterate over x the program crashes in the iteration loop. If I debug the
    > program I see that the Iterator has som strange value which I did not put
    > in. Finially I end up in the XString header where there seems to be some
    > kind of memory allocation problem. If I ask for the last pointer in x

    using
    > x.back() I get a good result. but x[x.size()-1] produces nonsense;
    >


    You have a bug in your program. I can promise you that it is not in the
    single line of code you have posted, but in one of the many lines of code
    you didn't post.

    > The problem stated does not occur in release mode.


    That is not unusual, in fact it is typical. One possibility is that you have
    an uninitialised variable which happens to get one value in debug mode and a
    different value in release mode.

    >
    > Does anaybody know what is going on.
    >


    You have a bug in your code.

    > I use VC6.0.
    >


    It has a very good debugger, use it. Alternatively post the code.

    john
     
    John Harrison, Nov 12, 2004
    #3
  4. Stijn Oude Brunink

    Ron Natalie Guest

    Stijn Oude Brunink wrote:
    > Hello
    >
    > I'm using std:vector to hold some pointers
    >
    > vector<CBase*> x;
    >

    You're hosing memory somewhere. You're really
    expecting us to be clairvoyant here given the tiny
    amount of information given, so I'll use my crystal
    ball....

    ....the mists surround me...

    Are you by any chance writing to positions in the vector
    that haven't yet been allocated?

    vector <CBase*> x;

    x[0] = 0; // Hey x.size() is still zero here!
     
    Ron Natalie, Nov 12, 2004
    #4
    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. Johannes Lebek
    Replies:
    1
    Views:
    2,055
    Johannes Lebek
    Jul 9, 2003
  2. Anonymous
    Replies:
    20
    Views:
    4,387
    Pete Becker
    Mar 30, 2005
  3. Replies:
    1
    Views:
    362
    Joe Kesselman
    Oct 7, 2006
  4. Jason Heyes
    Replies:
    8
    Views:
    754
    Andrew Koenig
    Jan 15, 2006
  5. Rune Allnor
    Replies:
    4
    Views:
    982
    Rune Allnor
    Dec 11, 2008
Loading...

Share This Page