Difference Between Debug and Release Mode

Started by
4 comments, last by giant 21 years, 6 months ago
Hi. I am very confused!!! Here is my problem, well the first on a long list. I am writing a Script Engine. As like most programmers, I want the most help I can get when developing, so I have Active Configuration set to Debug (MS Visual C++ V6 ). I developed the Engine, and got it to an acceptable level. It compiled with 0 Errors, and 0 Warnings. I wrote a script wich was 100% and parsed it, and it worked fine. The script was parsed and executed correctly, as was expected, since it was 100% correct. Then to see size and performance differences I set Active Configuration to Release, compiled the exact same code, and ran it again with the same Script. It compiled as before with 0 Errors, and 0 Warnings, however when I ran the exe, it took a different path through the program than before, and started producing output that it should not have. The script engine is not time dependent, so that is not an issue, so how can to programs compiled from the exact same code, and using the exact same input, with no randomness or timeing involved produce different output. If anyone can tell me, please do, cause I do not feel like debuging the Release Version, after spending so long with the Debug Verison. Thanks "Only two things are infinite, the universe and human stupidity, and I''m not sure about the former." --Albert Einstein
Advertisement
I think that the reason has to be an error somewhere in your parser. In debug mode the compiler uses a memory manager, and in release mode it does not.

So you have to look for errors in any code that has to do with pointers or new''d / deleted arrays.

I don''t know about VC++6, but my VC++5 does not initialize new''d arrays to 0, so after something like char* string = new char[100]; there''s just 100 bytes of garbage in it before i memset it.
But in debug mode all memory gets initialized to zero/NULL.

So your best bet is to search all char* and other arrays or pointers you have and memset/zeromemory them.

Also in release mode pointers don''t get set to NULL after deleting them. So if you have code like
delete somepointer;
if(somepointer) func1() else func2();
then in debug mode you are guaranteed that func2 will be executed, while in release mode the chance that func1 gets called is very high.

So at every location where you delete a pointer make sure you set it to NULL after deleting if there is a chance that it will be used for a comparison or something else later.


Hope that helps


Runicsoft -- home of my open source Function Parser and more
You will get this kind of error if you''re accessing an array out of bounds..

i.e.: x = 1; y = 1;

myArray[x-3][y] = 2;

This will not cause a compiler error, and may run in debug mode, but not release mode.
------------------http://www.nentari.com
Ahhhh, ok. Thanks guys. I go through my code and fix up all the constructors so that alsolutly everything is set to NULL.

Thanks
Giant

"Only two things are infinite, the universe and human stupidity, and I''m not sure about the former." --Albert Einstein
quote:Original post by giant
Ahhhh, ok. Thanks guys. I go through my code and fix up all the constructors so that alsolutly everything is set to NULL.


Use 0 and save three keystrokes


It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
quote:Original post by MadKeithV
Use 0 and save three keystrokes

You do realize you''re playing with fire now, don''t you?


The world holds two classes of men -- intelligent men without religion, and religious men without intelligence. - Abu''l-Ala-Al-Ma''arri (973-1057; Syrian poet)
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement