title: Is bounds checking in C or C++ expensive?
body: <blockquote>
    <p>Bound checking is expensive
    (> x2 times runtime overhead) </p>
  </blockquote>
  
  <p>I got this point above from one of my professors. I am confused about that. 
  As I know, the most time-consuming part of a program is IO(from network and from hard disks).</p>
  
  <p>But bounds checking in C or C++ are not always related with those 2 input sources.
  For example, I copy the content of one buff to another in C using <code>memcpy(dest, src, length(src))</code>. Before that, I check the size of <code>src</code> in order to prevent from a heap overflow. The precess I can image is: Get the start-address of <code>src</code> and the <code>\x00</code> byte in <code>src</code>(in the view of assembly language, I copy the content of <code>src</code> one by one and see if the byte is equivalent with <code>\x00</code>). After getting the 2 address, just substract them to get the length of <code>src</code>. I read the content of <code>src</code> from the memory. We all know reading things from memory is fast.</p>