tags:

views:

359

answers:

7

I'm currently working on a C++ program in Windows XP that processes large sets of data. Our largest input file causes the program to terminate unexpectedly with no sort of error message. Interestingly, when the program is run from our IDE (Code::Blocks), the file is processed without any such issues.

As the data is being processed, it's placed into a tree structure. After we finish our computations, the data is moved into a C++ STL vector before being sent off to be rendered in OpenGL.

I was hoping to gain some insight into what might be causing this crash. I've already checked out another post which I can't post a link to since I'm a new user. The issue in the post was quite similar to mine and resulted from an out of bounds index to an array. However, I'm quite sure no such out-of-bounds error is occurring.

I'm wondering if, perhaps, the size of the data set is leading to issues when allocating space for the vector. The systems I've been testing the program on should, in theory, have adequate memory to handle the data (2GB of RAM with the data set taking up approx. 1GB). Of course, if memory serves, the STL vectors simply double their allocated space when their capacity is reached.

Thanks, Eric

+1  A: 

What does your memory model look like? Are you banging up against an index limit (i.e. sizeof int)?

Robert Harvey
+9  A: 

The fact that the code works within the IDE (presumably running within a debugger?), but not standalone suggests to me that it might be an initialisation issue.

therefromhere
+5  A: 

Compiler with the warning level set to max.

Then check all your warning. I would guess it is an uninitialized variable (that in debug mode is being initialized to NULL/0).

Personally I have set my templates so that warnings are always at max and that warnings are flagged as errors so that compilation will fail.

Martin York
+2  A: 

You'd probably find it helpful to configure the O/S to create a crash dump (maybe, I don't know, still by using some Windows system software called "Dr Watson"), to which you can then attach a debugger after the program has crashed (assuming that it is crashing).

You should also trap the various ways in which a program might exit semi-gracefully without a crash dump: atexit, set_unexpected, set_terminate and maybe others.

ChrisW
A: 

Sounds like your program is throwing an exception that you are not catching. The boost test framework has some exception handlers that could be a quick way to localise the exception location.

Are there indices in the tree structure that could overflow? Are you using indexes into the vector that are beyond the current size of the vector?

new vector...    
vector.push_back()
vector.push_back()
vector[0] = xyz
vector[1] = abc
vector[2] = slsk // Uh,oh, outside vector

How large is your largest input set? Do you end up allocating size*size elements? If so, is your largest input set larger than 65536 elements (65536*65536 == MAX_INT)?

I agree the most likely reason that the IDE works fine when standalone does not is because the debugger is wiping memory to 0 or using memory guards around allocated memory.

Failing anything else, is it possible to reduce the size of your data set until you find exactly the size that works, and a slightly large example that fails - that might be informative.

Tom Leys
In theory I could pinpoint the exact size at which the error occurs, but as I mentioned in the comments to the original post, the test case is large enough so that this is unfeasible. The data set may, in fact, be large enough to hit the integer overflow, which I've put into the queue of things to check.
Eric
If you did want to find the right size, you would do a binary search - remove half the data, put a quarter back in, remove 1/8 of it, etc. This only works if removing / adding data is relatively easy.
Tom Leys
You nailed the problem on the head in your last sentence. The input file gets heavily manipulated into the data being put into the tree and eventually the vector. There's not really any way for me to eliminate any set amount from the final data set without doing some serious hacking to just throw out stuff well after data has been read in. Certainly a good suggestion in simpler cases though. Thanks for the continued help!
Eric
A: 

I'd recommend to try to determine approximately which line of your code does causes the crash.

Since this only happen outside your IDE you can use OutputDebugString to output the current position, and use DebugView.

Really the behavior of a program compiled for debug inside and outside of IDE can be completely different. They can use a different set of runtime libraries when a program is loaded from the IDE.

Recently I was bitten by a timing bug in my code, somehow when debugging from the IDE the timing was always good an the bug was not observed, but in release mode bam the bug was there. This kinda of bug are really a PITA to debug.

Ismael
A: 

As it turns out, our hardware is reaching its limit. The program was hitting the system's memory limit and failing miserably. We couldn't even see the error statements being produced until I hooked cerr into a file from the command line (thanks starko). Thanks for all the helpful suggestions!

Eric