Safe but slow STL


Recently we have implemented a parser to read / write triangulated surface data into a file. The parser works perfect in release mode (compiled by using Visual Studio 2008), but becomes tremendously slow in debug mode.  This started causing the huge loss in productivity of the team in debugging – as now just reading a geometry file in the software takes around 6 minutes compared to few seconds in release mode. This remained a problem for quite some time until we have discovered that its standard template library (STL) implementation that was causing this slowness.
The STL implementation on Windows platform has concepts of Checked Iterator and Debug Iterator These safe iterator helps in detecting following kind of problems in iterator usage:
·         Using an iterator that has been invalidated by collection modification
·         Using an iterator to attempt to access an element outside the bounds of a container
We observed that the implementation of safe iterator (especially the debug iterator) was making the overall software very slower. And, in the debug mode, the Checked and Debug iterator code is remains switched on by default. We disabled the safe iterator by changing the value of pre-processor _SECURE_SCL and _HAS_ITERATOR_DEBUGGING to 0.
In "C/C++ | Preprocessor" Add ;_SECURE_SCL=0;_HAS_ITERATOR_DEBUGGING=0 to Pre-processor Definitions for both Debug and Release. As a rule, expert suggests to set identical value for these pre-processor within a translation unit and a DLL.
With this change, the team was able to regain the productivity in normal debugging purposes.

Safe but slow STL Safe but slow STL Reviewed by Sourabh Soni on Sunday, November 14, 2010 Rating: 5

No comments

Author Details

Image Link [https://3.bp.blogspot.com/-zo21XIdyPqc/VuTrFfUyPhI/AAAAAAAAAO8/EEWTN73XHUA7aTIjuxuBSN-WGaGkNUymA/s1600/sourabhdots3.jpg] Author Name [Sourabh Soni] Author Description [Technocrat, Problem Solver, Corporate Entrepreneur, Adventure Enthusiast] Facebook Username [sourabh.soni.587] Twitter Username [sourabhs271] GPlus Username [#] Pinterest Username [#] Instagram Username [#] LinkedIn Username [sonisourabh] Youtube Username [sonisourabh] NatGeo Username [271730]