| delorie.com/archives/browse.cgi | search |
| X-Authentication-Warning: | delorie.com: mailnull set sender to djgpp-bounces using -f |
| From: | Lotko Mariusz <lotko AT alice DOT ci DOT pwr DOT wroc DOT pl> |
| 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: | <a6o05m$9nt$2@panorama.wcss.wroc.pl> |
| References: | <3C8CD04E DOT 5050105 AT vif DOT com> <a6im8f$61b$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> |
| NNTP-Posting-Host: | alice.ci.pwr.wroc.pl |
| Mime-Version: | 1.0 |
| 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 <broeker AT physik DOT rwth-aachen DOT de> wrote:
> Sahab Yazdani <sahaby AT vif DOT com> 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/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |