From 1150313290263526835
X-Google-Thread: f78e5,a10702d4a7db0a94
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news4.google.com!news3.google.com!news.glorb.com!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: "Greg Herlihy" <greghe@pacbell.net>
Newsgroups: comp.std.c++
Subject: Re: Why no size_t to ::operator delete?
Date: Sun, 24 Dec 2006 11:45:56 CST
Organization: http://groups.google.com
Lines: 31
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <1166953289.859132.240450@i12g2000cwa.googlegroups.com>
References: <12omt8jit7rl379@corp.supernews.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Trace: posting.google.com 1166953294 22176 127.0.0.1 (24 Dec 2006 09:41:34 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 24 Dec 2006 09:41:34 +0000 (UTC)
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.csse.unimelb.edu.au: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@mailman.ucar.edu
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: i12g2000cwa.googlegroups.com; posting-host=70.231.133.91;
   posting-account=JdllFQ0AAAC-QghphnHMZz5q0GHnzGUJ
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Xref: g2news2.google.com comp.std.c++:5162

Scott Meyers wrote:
> Can someone explain to me why having the "normal" operator delete take a
> size_t is impractical?

Since the implementation of a class-specific delete operator always has
the option of calling the global delete operator to perform the actual
deallocation, a class delete operator does have a good excuse for not
knowing the actual size of the block being deleted. Therefore, knowing
the size of the original allocation request very well could be
information that the class delete operator could not otherwise find out
on its own.

The global delete operator has no comparable back-up, there is no other
delete routine that it can call to free the memory - global delete must
free the block itself. And in order to free the block, the global
delete operator must know the size of the actual allocation; knowing
just the requested size alone (the value of the size parameter) is not
enough information to free the block. Even assuming that the value of
the size parameter is accurate in the first place. After all, the
correctness of a program's memory management should not depend upon the
faithful preservation of data points that are needlessly round-tripped
through the user program, or so I would think.

Greg

---
[ 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.comeaucomputing.com/csc/faq.html                      ]



