473,808 Members | 2,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1554
In article <11************ **********@g44g 2000cwa.googleg roups.com>,
ro**********@gm ail.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**********@gm ail.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**********@gm ail.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**********@gm ail.com wrote:
Kai-Uwe Bux wrote:
ro**********@gm ail.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**********@gm ail.com wrote:
Kai-Uwe Bux wrote:
ro**********@gm ail.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...obvious ly 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
1667
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. The two reasons are (1) that vector elements are smaller, since map elements need at least 3 pointers, and (2) contiguity of vector elements in memory ensure fewer page faults.
0
1083
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> TbarMap; TbarMap barMap_; barMap_ = TbarDerived1::CreateInstance;
5
1555
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 if this doesn't see correctly with non-HTML viewers) Ok, I'm fed up with this so I'll explain the situation here and my approach (which sucks), and see if anyone can give a better solution to this. I'm making a way to have several parameters...
1
1709
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 fieldname (name or age) and the values are stored as vectors in the indicated type (string, int). Like this i can call: result (= a string "Mac") or result (= an int of val 23)
5
1785
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 before, but it's nearly impossible to find. I'm having trouble using STL vectors, maps, ... in templated functions, when the templated class is a template parameter of the map too. Below is a (cannibalized) example of a class 'Model' which contains...
5
1892
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, NodePtr>::iterator NodeMapItr; NodeMap nmap; In my classes, I often find myself copying the second arguments of
15
3541
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 you want to make a deque which can contain any objects of any of those types. Normally what you would have to do is to make a deque or vector of pointers of the base class type and then allocate each object dynamically with 'new' and store the...
9
1701
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 overhead of the useless copies made each time the vector is resized is too large for me to ignore. I know that rvalue references fix this problem, but I don't think they'll be widely available for years and I need something that works now....
6
2333
by: amscompit | last post by:
I have a written the following code. #include<iomanip> #include<fstream> #include<vector> #include<cctype> using namespace std;
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10631
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10114
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9196
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.