473,396 Members | 2,052 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,396 software developers and data experts.

types containing vectors or maps

It is my understanding that if you contain vectors or maps you don't
need to create copy constructors because the default calls that
constructor. It is my understanding that if you use these types you
don't have to worry about them at all...even if the contents of your
map or vector may contain other maps or vectors. Am I mistaken in any
way?

We are running into a very strange bug that is avoiding detection by
hiding in the default allocator of std::vector. The crash occurs when
push_back reaches a point where it actually deletes the current vector
after creating the new one. None of the types contained within the
vector contain pointers they manage (there are std containers in one of
the eventual contents). Luckily this bug also doesn't happen if the
program is started in the debugger.

Feb 16 '06 #1
5 1529
In article <11**********************@g44g2000cwa.googlegroups .com>,
ro**********@gmail.com wrote:
It is my understanding that if you contain vectors or maps you don't
need to create copy constructors because the default calls that
constructor. It is my understanding that if you use these types you
don't have to worry about them at all...even if the contents of your
map or vector may contain other maps or vectors. Am I mistaken in any
way?
Right, as long as you don't have any of them holding pointers they will
take care of everything for you.
We are running into a very strange bug that is avoiding detection by
hiding in the default allocator of std::vector. The crash occurs when
push_back reaches a point where it actually deletes the current vector
after creating the new one. None of the types contained within the
vector contain pointers they manage (there are std containers in one of
the eventual contents). Luckily this bug also doesn't happen if the
program is started in the debugger.


You have a memory overwrite somewhere in your code, you are going to
have to go through it by eye and find out where an invalid pointer is
being dereferenced. IMPORTANT: the bug probably is *not* in the code
that crashes, or anywhere near it.

--
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.
Feb 16 '06 #2
ro**********@gmail.com wrote:
It is my understanding that if you contain vectors or maps you don't
need to create copy constructors because the default calls that
constructor.
You mean: if you *only* contain vectors or maps.
It is my understanding that if you use these types you
don't have to worry about them at all...even if the contents of your
map or vector may contain other maps or vectors. Am I mistaken in any
way?
Well, if your maps and vectors contain (by any level of indirection)
pointers of unknown origin, life gets harder.

We are running into a very strange bug that is avoiding detection by
hiding in the default allocator of std::vector. The crash occurs when
push_back reaches a point where it actually deletes the current vector
after creating the new one. None of the types contained within the
vector contain pointers they manage (there are std containers in one of
the eventual contents).
Just a wild speculation: maybe you keep an iterator that gets invalidated in
the reallocation of the vector. That could be an iterator to the vector
itself or to any container indirectly stored therein.

Do you have code you could post that shows the problem?

Luckily this bug also doesn't happen if the program is started in the
debugger.


"Luckily"?

Good luck.

Kai-Uwe Bux

Feb 16 '06 #3

Kai-Uwe Bux wrote:
ro**********@gmail.com wrote:
It is my understanding that if you contain vectors or maps you don't
need to create copy constructors because the default calls that
constructor.
You mean: if you *only* contain vectors or maps.


Well, no, there are also primatives.
It is my understanding that if you use these types you
don't have to worry about them at all...even if the contents of your
map or vector may contain other maps or vectors. Am I mistaken in any
way?
Well, if your maps and vectors contain (by any level of indirection)
pointers of unknown origin, life gets harder.

We are running into a very strange bug that is avoiding detection by
hiding in the default allocator of std::vector. The crash occurs when
push_back reaches a point where it actually deletes the current vector
after creating the new one. None of the types contained within the
vector contain pointers they manage (there are std containers in one of
the eventual contents).


Just a wild speculation: maybe you keep an iterator that gets invalidated in
the reallocation of the vector. That could be an iterator to the vector
itself or to any container indirectly stored therein.


I don't believe so. Nothing obvious anyway.
Do you have code you could post that shows the problem?
No, program is huge and proprietery and like Daniel said, it could be
anywhere; I really think something out there is hosing a buffer
somewhere and this vector is always in the way...which is odd
but...well I have no idea. I wasn't really expecting to be able to be
helped ;) Only if I was wrong about the above and I was damn sure I
wasn't but there was some discussion about it.
Luckily this bug also doesn't happen if the program is started in the
debugger.


"Luckily"?


Yeah, nice huh...We'll just tell the customers they have to run the
program in the debugger...yeah, that should work ;)

I don't envy my coworker :P

Feb 16 '06 #4
ro**********@gmail.com wrote:
Kai-Uwe Bux wrote:
ro**********@gmail.com wrote:

....
Luckily this bug also doesn't happen if the program is started in
the debugger.


"Luckily"?


Yeah, nice huh...We'll just tell the customers they have to run the
program in the debugger...yeah, that should work ;)

I don't envy my coworker :P


Perhaps your compiler is initializing memory when under debug, but not when
compiling optimized. I know MSVC allows this to be modified for debug builds
and/or allows generation of debug info for release/optimized builds. You may
be able to track down the problem in either of these modes.

Jeff Flinn
Feb 16 '06 #5

Jeff Flinn wrote:
ro**********@gmail.com wrote:
Kai-Uwe Bux wrote:
ro**********@gmail.com wrote:

...
Luckily this bug also doesn't happen if the program is started in
the debugger.

"Luckily"?


Yeah, nice huh...We'll just tell the customers they have to run the
program in the debugger...yeah, that should work ;)

I don't envy my coworker :P


Perhaps your compiler is initializing memory when under debug, but not when
compiling optimized. I know MSVC allows this to be modified for debug builds
and/or allows generation of debug info for release/optimized builds. You may
be able to track down the problem in either of these modes.


It was definately a buffer overrun. Heap corruption caused by someone
doing something like:

char * p = new char[strlen(x) + y];
char * p2 = new char[strlen(p) + y];

Don't ask me why that was in there...obviously a typo of some sort but
the way the guy found it was by using this:
http://support.microsoft.com/?id=286470

Feb 16 '06 #6

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

Similar topics

12
by: Fred Ma | last post by:
Hello, I was looking at Meyers's "Effective STL", item 23 about choosing between vectors and maps (at least that the choice for me). In many cases, using sorted vectors is faster for lookups. ...
0
by: Simon Elliott | last post by:
I have a class factory which maps various parameters onto static creator functions: typedef TbarAutoPtr (*TcreateBar)(const std::string& barName); typedef std::map <std::string, TcreateBar>...
5
by: Javier Campos | last post by:
WARNING: This is an HTML post, for the sake of readability, if your client can see HTML posts, do it, it doesn't contain any script or virus :-) I can reformat a non-HTML post if you want me to (and...
1
by: Dekker | last post by:
Hi I would like to transform the result of a csv-string (eg.: "name,age\nstring,int\nMac,23\nMax,24\nMike,78") into a map of vectors map<string, vector<???> >. The key of the map will be the...
5
by: DrLex | last post by:
This is a really annoying thing to look up in Google because all pages that mention STL maps or vectors will most likely also contain the word "template". So maybe this question has been asked...
5
by: pallav | last post by:
I have a map like this: typedef boost::shared_ptr<NodeNodePtr; typedef std::vector<NodePtrNodeVecPtr; typedef std::map<std::string, NodePtrNodeMap; typedef std::map<std:string,...
15
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and...
9
by: Ben Rudiak-Gould | last post by:
Background: I have some structs containing std::strings and std::vectors of other structs containing std::strings and std::vectors of .... I'd like to make a std::vector of these. Unfortunately the...
6
by: amscompit | last post by:
I have a written the following code. #include<iomanip> #include<fstream> #include<vector> #include<cctype> using namespace std;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.