title: How to replace malloc with new in example
body: <p>I'm following a C++ msdn reference for Managing IP Addresses. The memory allocation in the example is using malloc instead of new. It is my understanding that malloc should never be used in C++. How would I go about converting these malloc's into new ?</p>
  
  <p>Link: <a href="http://msdn.microsoft.com/en-us/library/aa366309%28v=vs.85%29.aspx" rel="nofollow">MSDN REFERENCE</a></p>
  
  <p>The code in question:</p>
  
  <pre><code>MIB_IPADDRTABLE  *pIPAddrTable;
  DWORD            dwSize = 0;
  DWORD            dwRetVal;
  
  pIPAddrTable = (MIB_IPADDRTABLE*) malloc( sizeof(MIB_IPADDRTABLE) );
  
  if (GetIpAddrTable(pIPAddrTable, &amp;dwSize, 0) == ERROR_INSUFFICIENT_BUFFER)
  {
      free( pIPAddrTable );
      pIPAddrTable = (MIB_IPADDRTABLE *) malloc ( dwSize );
  }
  
  if ( (dwRetVal = GetIpAddrTable( pIPAddrTable, &amp;dwSize, 0 )) != NO_ERROR )
  { 
      printf("GetIpAddrTable call failed with %d\n", dwRetVal);
  }
  
  printf("IP Address:         %ld\n", pIPAddrTable-&gt;table[0].dwAddr);
  printf("IP Mask:            %ld\n", pIPAddrTable-&gt;table[0].dwMask);
  printf("IF Index:           %ld\n", pIPAddrTable-&gt;table[0].dwIndex);
  printf("Broadcast Addr:     %ld\n", pIPAddrTable-&gt;table[0].dwBCastAddr);
  printf("Re-assembly size:   %ld\n", pIPAddrTable-&gt;table[0].dwReasmSize);
  
  if (pIPAddrTable)
      free(pIPAddrTable);
  </code></pre>