--- In [email protected], "Joseph A. Marrero" <[EMAIL PROTECTED]> wrote: > > Hmmm. Thats pretty interesting. On MS Windows, malloc and > new internally use the same function (I can't remember the > name) to allocate memory. So, I would think they would be > compatible in most cases where constructors/destructors are > not involved. I use malloc in legacy C libraries that I > still use in my C++ projects and have not ever noticed a > problem in the past. > > In short, I agree malloc should not be used in C++ code > except for cases where you are explicitly using C code > within a C++ project. I could be wrong... who knows. > > --- Nico Heinze <[EMAIL PROTECTED]> wrote: > > > --- In [email protected], "Paul Herring" > > <pauljherring@> wrote: > > > > > > On 12/28/06, Nico Heinze <grollnar@> 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.
Frankly spoken I was not talking about Windows; in fact I have experienced this trouble on a Solaris system two years ago, so it may be that meanwhile this behaviour has been remedied. What I wanted to express is that you should not rely on such mixes to work under all circumstances. Regards, Nico
