strang behaviour std:vector and XString in VC6.0

S

Stijn Oude Brunink

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
 
C

chris

Stijn said:
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
 
J

John Harrison

Stijn Oude Brunink said:
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
 
R

Ron Natalie

Stijn said:
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!
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top