From: jhw AT wetware DOT com (strychnine) Newsgroups: alt.msdos.programmer,comp.os.msdos.djgpp,rec.games.programmer Subject: Re: C or C++ Date: Wed, 28 May 1997 12:58:27 -0800 Organization: Dr. Strychnine's Box of Sharpened Springs Message-ID: References: <5lrt2d$qun AT bambam DOT soi DOT city DOT ac DOT uk> <5mftso$2nc AT butch DOT lmms DOT lmco DOT com> <338C31B9 DOT 3146 AT ll DOT mit DOT edu> NNTP-Posting-Host: 199.108.64.194 Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Lines: 21 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In article <338C31B9 DOT 3146 AT ll DOT mit DOT edu>, Nathan Gray 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