Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Release build seg faults at vector push_back

Status
Not open for further replies.

ranadhir

Programmer
Nov 4, 2003
54
IN
i'm currently experiencing a strange problem under vc++ .NET 7.0. i hope
someone has a hint for me, i'm kind of lost atm.

i'm using a vector of object instances in my code.
using the release build,I get a runtime error intermittently while adding to the vector using push_back.
When i use the debug build. i can add
as much elements as i want without any problems .

Is there any special setting to be done for reease build?

It is is simple as
EMEventContainer instance("key","value");
this_vector.push_back(instance);

But it does not work properly in release build.
 
Does your EMEventContainer copy correctly? Post the class if possible, or if it is too big just the member variables and the implementation of any copy constructor and/or copy assignment operator you've written.
 
EMEventContainer contains std:string member variables.
I have not declared explicit copy constructor or assignment operator for this.Is that the problem?
 
If it only contains std::string member variables, then no explicit copy constructor or assignment operator are necessary, so that shouldn't be the problem.

It is very unlikely that there is a bug in the vector code, so you just have to figure out where you've gone wrong. Often a Release error that doesn't show up in the debug build is due to uninitialized variables. VC++ sometimes sets variables to 0 in the debug build but not in release.

Is the vector a member of another class? Is it possible that whatever function it is in is being called on an invalid object? That would be my best guess as to why the error shows up with the vector.
 
I am constructing the EMEventContainer instance as
EMEventContainer emcontainer(OLE2A(elem),OLE2A(elemtype),OLE2A(event),OLE2A(toUrl));
where the input params are of type CComBSTR.
Do i need to append a detach before i implement the macro OLE2A to convert into string?
 
I have read that in the release build the method of allocating stack to the local variables are different ;and therefore all variables need to be initialized.
Maybe this is not directly relevant to this - but I am exploring all the possibilities.
In that case,is there a nee to initialize COM macros like CCOMPtr,CComQIPtr, and CCOMBSTR.
I use them as local varialbes to a large extent.
 
I'm sorry ranadhir, I don't really have experience or knowledge in your COM stuff, so I can't help you with that part. Good luck!
 
> I get a runtime error intermittently while adding to the vector using push_back.
Random memory problems are "cause" and "effect".

What you're observing is the effect, which despite all attempts at inspection seems to be completely fine (and probably is if you've spent a good deal of time looking at it).

The cause is another matter, that's much harder to figure out. All that can be said is that it's somewhere before the effect, which doesn't really help much if your code has been running for hours.

A couple of suggestions.
In debug mode, use this to make sure you have no overruns and no leaks (or at least very few). Occasional off-by-1 errors in memory allocations do not usually show up in debug as memory sizes are often padded for alignment purposes. The checking routines should check for such problems.

In release mode, try Purify.
Such tools have a good payback if they find even one problem in a few hours which might take you a few days to find manually.

Do you have a previous version of the code in source control which "worked", and have you compared the differences. This is not to say that the previous one was bug-free, it could have been there a while and it's only the most recent change which has flushed it out. Still, examining the changes may offer some clues.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top