title: how to check if memory is allocated using malloc or new
body: <p>I am dealing with some legacy C/C++ code where memory is allocated using <code>malloc</code> as well as using <code>new</code>. I want to create a generalized wrapper function to deallocate the memory using either <code>free</code> or <code>delete []</code> , depending on how it is allocated. </p>
  
  <p>Is there a way to determine how memory is allocated ? Here is a pseudo code. </p>
  
  <pre><code>double *x;
  double *y;
  x = (double *) malloc(size);
  y = new double [size]
  
  doSomething();
  deallocateMemory(x, y);
  </code></pre>
  
  <p>I want <code>deallocateMemory</code> to determine whether to call <code>free</code> or <code>delete []</code> . Any help would be appreciated. </p>