Mail Archives: djgpp/1997/05/28/17:36:58
In article <338C31B9 DOT 3146 AT ll DOT mit DOT edu>, Nathan Gray <gray AT ll DOT mit DOT edu> wrote:
>
> Since we're on the subject of C and C++, does anyone have a good
> explanation for the differences between malloc() and new? As a native
> C++ programmer, my first instinct is to use new, but I see malloc() so
> often I'm starting to wonder if I'm missing something.
new/delete invoke constructors and [virtual] destructors. malloc/free
don't. so you lose type safety by using malloc/free.
on the other hand, malloc/free are compatible with realloc. new/delete
aren't. so it makes sense to use malloc/free when working with arrays of
builtins that you intend to dynamically resize with realloc.
new/delete are operators. malloc/free are extern "C" functions. this
difference is... subtle... and has to do with overloading.
--
juliet hotel whiskey at whiskey echo tango whiskey alfa romeo echo
[sgi|mips|daver|indetech]!wetware!jhw
"Perhaps today is not such a good day to die." --Ambrose MacClaine
- Raw text -