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"
> <[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
> 
> 


_________________
Joseph A. Marrero
http://www.l33tprogrammer.com/

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to