Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > strang behaviour std:vector and XString in VC6.0

Reply
Thread Tools

strang behaviour std:vector and XString in VC6.0

 
 
Stijn Oude Brunink
Guest
Posts: n/a
 
      11-12-2004
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


 
Reply With Quote
 
 
 
 
chris
Guest
Posts: n/a
 
      11-12-2004
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
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      11-12-2004

"Stijn Oude Brunink" <(E-Mail Removed)> wrote in message
news:3Q1ld.1069$(E-Mail Removed)...
> 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


 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      11-12-2004
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Announcing a Preview of XString, an XML technology - XML as a String wgilreath@gmail.com XML 1 10-07-2006 04:23 PM
Very Strang XML problem Tjerk Wolterink XML 1 11-12-2004 05:28 PM
Strang problem during vcr recording of a dvd. .Jack Brody DVD Video 5 06-28-2004 06:11 AM
a strang problem when i change a globe variable's value David Java 4 09-12-2003 05:37 AM
XALAN: ClassCastException: org.apache.xpath.objects.XString -- a bug? Johannes Lebek XML 1 07-09-2003 04:07 PM



Advertisments