title: Are there any advantages to using calloc() instead of a malloc() and memset()?
body: <p>I was wondering whether <code>calloc()</code> is preferable to a <code>malloc</code> followed by a <code>memset</code>.  The latter appears to be the most common way of allocating and initializing memory.</p>
  
  <p>A <a href="https://github.com/search?q=calloc&amp;type=Code" rel="nofollow noreferrer">github code search</a> turns up many <code>calloc</code> test and implementations but in the first number of pages no code actually using <code>calloc</code>.</p>
  
  <p>Does anyone who knows of any projects/organizations that use or recommend using <code>calloc</code> and the circumstances where recommend it?</p>
  
  <p>From the comments and answers below, here's some the thoughts that have emerges so far:</p>
  
  <ul>
  <li><p><code>calloc(n, size)</code> can prevent overflow that is possible with <code>malloc(n * size)</code></p></li>
  <li><p>combining <em>malloc</em> and <em>memset</em> gives <em>calloc</em> a chance to request a page that is known to already be zeroed.</p></li>
  <li><p>a disadvantage to <em>calloc</em> that the combined steps may preclude other wrappers around <em>malloc</em>.</p></li>
  </ul>