From 1255969866566680117
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,2847ea2daacb5072
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2004-04-17 10:36:21 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: qg4h9ykc5m@yahoo.com (David Olsen)
Newsgroups: comp.std.c++
Subject: Re: Proposal: free() and delete/delete[] compatibility
Date: Sat, 17 Apr 2004 17:36:19 +0000 (UTC)
Lines: 43
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <c5q88e$4j6k6$1@ID-214800.news.uni-berlin.de>
References: <c5pk7v$so3$1@ulysses.noc.ntua.gr>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: mail2news.demon.co.uk 1082223379 15774 10.0.0.1 (17 Apr 2004 17:36:19 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Sat, 17 Apr 2004 17:36:19 +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 1BEtjm-00046H-00
	for mail2news@news.news.demon.net; Sat, 17 Apr 2004 17:36:18 +0000
X-Received: from mulga.cs.mu.OZ.AU (localhost [127.0.0.1]) by mulga.cs.mu.OZ.AU with ESMTP
	id i3HHaGi2014292; Sun, 18 Apr 2004 03:36:16 +1000 (EST)
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i3HHaFTq014278;
	Sun, 18 Apr 2004 03:36:15 +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-Orig-NNTP-Posting-Host: bi01p1.co.us.ibm.com (32.97.110.142)
X-Orig-X-Trace: news.uni-berlin.de 1082172494 4823686 I 32.97.110.142 ([214800])
X-User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007
X-Accept-Language: en-us, en
X-Spamscanner: mailbox4.ucsd.edu  (v1.4 Mar 10 2004 15:18:19, 5.6/5.0 2.63)
X-MailScanner: PASSED (v1.2.8 35237 i3H3SFv6041655 mailbox4.ucsd.edu)
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=2.3 required=5.2 tests=FORGED_YAHOO_RCVD,
	FROM_HAS_MIXED_NUMS,FROM_HAS_MIXED_NUMS3 autolearn=no 
	version=2.60-mulga_r1
Xref: archiver1.google.com comp.std.c++:1724

Ioannis Vranos wrote:
> Proposal: A guarantee in the standard that if you call free() upon
> objects created by new/new[] ,and a call of delete/delete[] on
> objects created by malloc()/calloc()/realloc() is safe.
> 
> I am not talking about the constructors issue where they are not
> called in the case of malloc() family, just the interchange ability
> between free() and the delete family.

I immediately see two problems, apart from the constructor/destructor 
problem:

1. The program may have its own user-defined versions of operator new 
and operator delete, and these don't have to use malloc/free.  So the 
proposed guarantee can't apply when user-defined versions of the 
operators are used.  But when writing code that uses new and delete, 
there is no way to force the standard versions of operator new and 
operator delete to be used, so there is no way to know for sure that the 
guarantee applies.

2. A "new" expression that allocates an array is allowed to allocate 
some extra space at the front of the array.  This is usually done to 
store the number of items in the array so delete[] will call the 
destructor the correct number of times.  A delete[] expression knows 
about this and knows how to correctly adjust the pointer that it passes 
to operator delete[].  So, assuming that operator new[] calls operator 
new, which calls malloc, and given the following code:
	T *x = new T[10];
	free((void*)x);
The address returned by malloc (within operator new) might not be the 
address that is passed to free.  So therefore the guarantee can't apply 
to new[] and delete[].

-- 
David Olsen
qg4h9ykc5m@yahoo.com

---
[ 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                       ]



