From 1261641048946743311
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,2847ea2daacb5072
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2004-04-20 11:03:01 PST
Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: kuyper@wizard.net (James Kuyper)
Newsgroups: comp.std.c++
Subject: Re: Proposal: free() and delete/delete[] compatibility
Date: Tue, 20 Apr 2004 18:03:00 +0000 (UTC)
Organization: http://groups.google.com
Lines: 53
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <8b42afac.0404200949.74388665@posting.google.com>
References: <c5pk7v$so3$1@ulysses.noc.ntua.gr> <c5po2d$1582$1@ulysses.noc.ntua.gr> <8b42afac.0404190833.18bdf219@posting.google.com> <c61bqe$2k5u$1@ulysses.noc.ntua.gr>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1082484180 3514 10.0.0.1 (20 Apr 2004 18:03:00 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Tue, 20 Apr 2004 18:03:00 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 1BFzaF-0000uX-00
	for mail2news@news.news.demon.net; Tue, 20 Apr 2004 18:03:00 +0000
X-Received: from mulga.cs.mu.OZ.AU (localhost [127.0.0.1]) by mulga.cs.mu.OZ.AU with ESMTP
	id i3KI2vi2029437; Wed, 21 Apr 2004 04:02:57 +1000 (EST)
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i3KI2v3U029428;
	Wed, 21 Apr 2004 04:02:57 +1000 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: Tue, 20 Apr 2004 17:49:33 +0000 (UTC)
X-Spam-Level: 
X-Spam-Checker-Version: SpamAssassin 2.60-mulga_r1 (1.212-2003-09-23-exp) on 
	mulga.cs.mu.OZ.AU
X-Spam-Status: No, hits=0.0 required=5.2 tests=AWL autolearn=no 
	version=2.60-mulga_r1
Xref: archiver1.google.com comp.std.c++:1787

ivr@guesswh.at.emails.ru ("Ioannis Vranos") wrote in message news:<c61bqe$2k5u$1@ulysses.noc.ntua.gr>...
> "James Kuyper" <kuyper@wizard.net> wrote in message
> news:8b42afac.0404190833.18bdf219@posting.google.com...
> >
> > > The proposal corrected:
> > >
> > > Proposal: A guarantee in the standard that if you call delete/delete[]
>  on
> > > objects created by
> > > malloc()/calloc()/realloc() is safe.
> >
> > The whole point of the new/delete feature of C++ is to maintain a
> > tight connection between the lifetime of an object, and the validity
> > of it's contents, even when that object is dynamically allocated. A
> > successfull new-expression creates an object, filled in by a
> > constructor with valid values. A successful delete of that same object
> > undoes whatever needs to be undone, to bookend the code in the
> > constructor, and then releases the memory. People deliverately and
> > correctly design objects so that if you don't execute constructors and
> > destructors as bookend code, things go wrong.
> > Therefore, in order to make it possible to free() an object created
> > with new, free() would to run the corresponding destructor. In that
> > case, why bother? Why not delete it?
> 
> 
> Please read more carefully the corrected version of my proposal above.


> Proposal: A guarantee in the standard that if you call delete/delete[] on
> objects created by
> malloc()/calloc()/realloc() is safe.

malloc()/free() is the bookend pair you use when you want to seperate
dynamic allocation of memory from construction and destruction of
objects in that memory. new/delete is the bookend pair you use when
you want to tie allocation/deallocation closely together with
construction/destruction. Who's responsible for deallocation when you
use malloc()/delete?

If delete always calls the destructor, than it would have to be an
error to delete malloc()d memory unless an object of the appropriate
type has been constructed in-place in that memory. If delete is
supposed to call the destructor for objects allocated with new, and
not for objects allocated with malloc(), how is it supposed to know
which is which? It wouldn't be impossible to implement that, but it
would require a lot of changes.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



