--- In [email protected], "Paul Herring" <[EMAIL PROTECTED]> wrote: > > On 12/28/06, Nico Heinze <[EMAIL PROTECTED]> wrote: > > > 4) I know that many people don't trust my words here, > > but the result of mixing new/delete with malloc/calloc/free > > is compiler and runtime specific; sometimes it works without > > hassle, in other cases it can easily kill your server > > applications without any chance to find out why. > > It is perfectly Legal[tm] to have both new/delete and > malloc/free in the same program. What is undefined is > deleting a malloced pointer and freeing a newed pointer. > (And incidentally, and slightly OT, is delete[]ing a newed > pointer and deleting a new[]ed pointer) <snip>
Though it is legal, I have experienced a case where using new/delete and malloc()/free() in the same program crashed the application. After having removed all free() calls and re-ordered everything such that only a very few malloc() calls took place at the beginning of the application and afterwards only new/delete were used, everything ran fine until I had to upgrade from Sun Forte 4.0 to Forte 5; at that point I had to get rid of the malloc() stuff completely, otherwise I would not have been able to upgrade the remainder of the application. In short: even though it's legal, never rely on malloc()/free() and new/delete working within the same application. It might work for your system, but it need not. Regards, Nico
