I am working on a program (using MS Visual Studio 2005 professional) and have incorporated some Standard Template Library vectors. The program is very math intensive. When I run in debug mode, the debug checking provided by STL slows the program to the point that I am getting no work done. The program is slowed by almost a factor of 100. What takes 35 sec in release mode takes almost an hour in debug.

The part that uses the vectors is already working fine, but I have to process through that to get to the part that still needs to be debugged.

I have tried setting
#define _HAS_ITERATOR_DEBUGGING 0
#define _SECURE_SCL 0

and I have also used an #undef for each of these values prior to setting them. There is no difference in performance.

Is there any way to turn off the debug checking for STL vectors?

Thank you, but this isn't an efficiency issue.

STL provides bounds checking for container iterators. When the bounds checking is turned on, a lot more code is executed and the code slows down. With a math intensive application (in my case, I'm doing a lot of cross-correlation of vectors), the bounds checking overhead can be very costly.

The bounds checking behavior is turned on by compiling in debug mode and is turned off by compiling in release mode. What I want to do is turn off the bounds checking for the vectors (which can obviously be done), but retain the remaining symbolic debugging capability of working in debug mode. The cross-correlation functions are already working properly and don't need bounds checking. But I need to run that portion of the program to get to the part that does still need work. Waiting an hour to hit a breakpoint just doesn't cut it.

How about putting the code that works ok into a static library and compile for release. Then the remaining code in the application program which is compiled for debug. Finally link the two.

I suggested the optimize pragma because I don't think the compiler will do stack or bounds checking with it turned on.

This article has been dead for over six months. Start a new discussion instead.