Checked Iterators

Microsoft Visual Studio versions since VC8 (VS2005) offer a feature called “checked iterators”. The MSDN documentation clearly states: “Checked iterators ensure that you do not overwrite the bounds of your container. Checked iterators apply to release builds and debug builds.Checked iterators can be disabled #defining the _SECURE_SCL symbol to 0.

In VC8 (VS2005) and VC9 (VS2008), checked iterators are enabled by default in both debug and release builds. While I agree that having checked iterators enabled by default in debug builds is a good thing (because debug builds are designed to catch as much bugs as possible), I think the default behavior in release builds should be to switch checked iterators off. In fact, I do like speed in release builds.

As a simple benchmark (attached to this blog post), on an Intel Core 2 Duo @ 2.33 GHz, switching checked iterators off improved a simple 1,000×1,000 matrix multiplication time from 20 seconds to about 12 seconds (a 40% improvement).

I like putting the following lines in precompiled header file, to switch checked iterators off in release builds:

// Disable checked iterators in release builds

#ifndef _DEBUG

#define _SECURE_SCL 0



Fortunately, in VS2010, in release mode, the default value for _SECURE_SCL is 0.

Leave a Reply

Your email address will not be published. Required fields are marked *