memory faults in debug mode
Hi
I have a strange problem.
When i run my program in release mode, it runs just fine, but when in debug mode, i get lots of memory exceptions.. any ideias why??
thanks
Bruno
Some compilers (like Visual C++ for example) do additional memory checks in debug mode. If you have for example done the following:
In release builds this will work fine most of the time. In debug builds you will get an exception in the delete [] call, because the debugger fills all the heap memory with 0xcd and the stack memory with 0xdd (or perhaps the other way around). If a memory block is freed the debug version of delete checks if the memory before and after the freed block is modified. If it is you Have Done Something Bad.
Well, I hope this helps you...
BYTE * p;p = new BYTE[100];p[100] = 45;delete [] p;
In release builds this will work fine most of the time. In debug builds you will get an exception in the delete [] call, because the debugger fills all the heap memory with 0xcd and the stack memory with 0xdd (or perhaps the other way around). If a memory block is freed the debug version of delete checks if the memory before and after the freed block is modified. If it is you Have Done Something Bad.
Well, I hope this helps you...
Thanks for the info.
I found the problem.., it was in the Project->setting->code generation.
In debug mode in the use run-time library the option was:Debug Single-Threaded., in realease was just Single-Threaded.
I just change the runtime library in the debug mode to Single-Threaded and now works just fine...
Do you know why?
Bruno
I found the problem.., it was in the Project->setting->code generation.
In debug mode in the use run-time library the option was:Debug Single-Threaded., in realease was just Single-Threaded.
I just change the runtime library in the debug mode to Single-Threaded and now works just fine...
Do you know why?
Bruno
I''m not sure but I guess by using single threaded, no debug you disabled the memory corruption checks I mentionend above. The debug builds are only slower, they should not cause any runtime errors. If they throw an exception, you have done something bad somewhere. In release builds, it might not always crash the system like the debug builds, but it might make the system unstable, corrupt some other of your data or crash your system under some rare conditions.
I have found a very subtle error because of the debug mode myself:
I made a small error in my random() function which caused it to return numbers in the range 0-n instead of 0-(n-1). Because of that I wrote sometimes one byte too far in an array. Without the debug build I would have never found it (or known of its existence).
Do yourself a favour and go bug hunting. It might take a long time (this one above cost me nearly a day...) but in the long run it will save a LOT of trouble.
Only a dead bug is good bug.
I have found a very subtle error because of the debug mode myself:
I made a small error in my random() function which caused it to return numbers in the range 0-n instead of 0-(n-1). Because of that I wrote sometimes one byte too far in an array. Without the debug build I would have never found it (or known of its existence).
Do yourself a favour and go bug hunting. It might take a long time (this one above cost me nearly a day...) but in the long run it will save a LOT of trouble.
Only a dead bug is good bug.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement