title: Understanding "Buffer Security Check /GS" compiler option in MSVC++
body: <p>I was recently surprised to note that compiling with <code>/GS</code> (Enable buffer security check) in MSVC++ 2010 seems to have a non-negligible effect on run-time performance in some cases. Has anyone else had this experience??</p>
  
  <p>For a large scientific-style application (a mesh generation library) it seems that compiling with <code>/GS-</code> can lead to almost 10% improvements in run-time for several of the large benchmarks in my test suite ("large" being >= 1 second worth of run-time). <code>/GS</code> is on by default at all levels of optimisation in MSVC++ 2010.</p>
  
  <p>I must admit that I'd never paid too much attention to this option before, and I'm wanting a bit of clarification as to what it actually does. The online <a href="http://msdn.microsoft.com/en-us/library/Aa290051" rel="noreferrer">documentation</a> seems to talk extensively about string buffers, but since I don't use <code>string</code> or <code>char[]</code> buffers anywhere I must be missing something.</p>
  
  <p>This paragraph (from the online doc) seems to indicate that the performance degradation I'm seeing is a bit unusual:</p>
  
  <blockquote>
    <p>A performance tradeoff for using
    security checks in an application must
    be made. The Visual C++ compiler team
    focused on making the performance
    degradation small. In most cases, the
    performance should not degrade more
    than 2 percent. In fact, experience
    has shown that most applications,
    including high-performance server
    applications, have not noticed any
    performance impact.</p>
  </blockquote>
  
  <p>Of course I can just turn it off, and get faster code, but I want to understand the implications before I do that.</p>