473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

strang behaviour std:vector and XString in VC6.0

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
Jul 22 '05 #1
3 1941
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
Jul 22 '05 #2

"Stijn Oude Brunink" <so**********@chello.nl> wrote in message
news:3Q***************@amsnews02.chello.com...
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
Jul 22 '05 #3
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!
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Jason Heyes | last post by:
To my understanding, std::vector does not use reference counting to avoid the overhead of copying and initialisation. Where can I get a reference counted implementation of std::vector? Thanks.
18
by: Janina Kramer | last post by:
hi ng, i'm working on a multiplayer game for a variable number of players and on the client side, i'm using a std::vector<CPlayer> to store informatik about the players. CPlayer is a class that...
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
17
by: Michael Hopkins | last post by:
Hi all I want to create a std::vector that goes from 1 to n instead of 0 to n-1. The only change this will have is in loops and when the vector returns positions of elements etc. I am calling...
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
32
by: zl2k | last post by:
hi, c++ user Suppose I constructed a large array and put it in the std::vector in a function and now I want to return it back to where the function is called. I can do like this: ...
56
by: Peter Olcott | last post by:
I am trying to refer to the same std::vector in a class by two different names, I tried a union, and I tried a reference, I can't seem to get the syntax right. Can anyone please help? Thanks
9
by: aaragon | last post by:
I am trying to create a vector of type T and everything goes fine until I try to iterate over it. For some reason, the compiler gives me an error when I declare std::vector<T>::iterator iter;...
13
by: jubelbrus | last post by:
Hi I'm trying to do the following. #include <vector> #include <boost/thread/mutex.hpp> #include <boost/shared_ptr.hpp> #include <boost/tuple/tuple.hpp> class {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.