title: shared_ptr with malloc and free
body: <p>I have working in large application which contain c and cpp. The all files saved as cpp extension but the code is written in c- style. I mean it is define structure rather than class allocate memory through malloc and realloc and calloc.In recent They have installed boost library So I am planning to use into my existing code base So I have some following question.</p>
  
  <ol>
  <li>Can I use std::shared_ptr with malloc and free.  </li>
  <li>If yes, can anyone point out me sample code base?</li>
  <li>Will it impact any functionality if I create std::shared_ptr in my application and pass this pointer to another function, which uses malloc or calloc?</li>
  </ol>
  
  <p>Or in other words:</p>
  
  <p>How do I achieve the similar functionality with std::shared_ptr, for the following code:</p>
  
  <pre><code>void allocateBlocks(int **ptr, int *cnt)
  {
      *ptr = (int*)malloc(sizeof(int) * 10);
      *cnt = 10;
      /*do something*/ 
  }
  
  int main()
  {
      int *p = NULL;
      int count = 0;
      allocateBlocks(&amp;p, &amp;count);
      /*do something*/
  
      free(p);
  }
  </code></pre>
  
  <p>We call some functions, which accept double pointer and fill the structure inside their application and use malloc. Can we assign those pointer to std::shared_ptr? For example:</p>
  
  <pre><code>typedef struct txn_s
  {
      int s;
      int d;
      int *e;
  } txn_t;
  
  typedef boost::shared_ptr&lt;txn_t&gt; tpointer;
  
  tpointer((txn_t*)::malloc(sizeof(txn_t),::free));
  </code></pre>