title: When and why will a compiler initialise memory to 0xCD, 0xDD, etc. on malloc/free/new/delete?
body: <p>I know that the compiler will sometimes initialize memory with certain patterns such as <code>0xCD</code> and <code>0xDD</code>.  What I want to know is <strong>when</strong> and <strong>why</strong> this happens.</p>
  
  <p><H2>When</H2></p>
  
  <p>Is this specific to the compiler used?</p>
  
  <p>Do <code>malloc/new</code> and <code>free/delete</code> work in the same way with regard to this?</p>
  
  <p>Is it platform specific?</p>
  
  <p>Will it occur on other operating systems, such as <code>Linux</code> or <code>VxWorks</code>?</p>
  
  <p><H2>Why</H2></p>
  
  <p>My understanding is this only occurs in <code>Win32</code> debug configuration, and it is used to detect memory overruns and to help the compiler catch exceptions.</p>
  
  <p>Can you give any practical examples as to how this initialization is useful?</p>
  
  <p>I remember reading something (maybe in Code Complete 2) saying that it is good to initialize memory to a known pattern when allocating it, and certain patterns will trigger interrupts in <code>Win32</code> which will result in exceptions showing in the debugger.</p>
  
  <p>How portable is this?</p>