X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f From: Lotko Mariusz Newsgroups: comp.os.msdos.djgpp Subject: Re: new/malloc and delete/free Date: 13 Mar 2002 16:53:10 GMT Organization: Politechnika Wroclawska Lines: 48 Message-ID: References: <3C8CD04E DOT 5050105 AT vif DOT com> NNTP-Posting-Host: alice.ci.pwr.wroc.pl Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: 8bit X-Trace: panorama.wcss.wroc.pl 1016038390 9981 156.17.10.4 (13 Mar 2002 16:53:10 GMT) X-Complaints-To: abuse AT news DOT pwr DOT wroc DOT pl NNTP-Posting-Date: 13 Mar 2002 16:53:10 GMT X-Newsreader: TIN [UNIX 1.3 unoff BETA 970304; sun4u SunOS 5.6] To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hans-Bernhard Broeker wrote: > Sahab Yazdani wrote: > > okay i've been using both c/c++ for a while, but this question just > > occured to me now, what exactly is the difference between new and > > malloc and delete and free. > In a very small nutshell: new/delete is just malloc/free with a shiny > C++ coat wrapped around it. > -- > Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) > Even if all the snow were burnt, ashes would remain. I'm afraid it's not true. new/delete call constructor/destructor while malloc/free don't. You can't mix new with free or malloc with delete. To state a point: class A { public: A() { string = "This won't be created by free()"; } ~A() { string = 0; } protected: char* string; }; So now: A* ptr = new A(); is quite different from: A* ptr = malloc( sizeof(A) ); // I'm not sure if such // strange thing works. -- -- Mariusz Lotko http://www.lotko.magma-net.pl/