Re: Commit: Re: patch: one-liner for 1134


Subject: Re: Commit: Re: patch: one-liner for 1134
From: Stuart D. Gathman (stuart@bmsi.com)
Date: Fri Mar 30 2001 - 14:58:04 CST


Patrick Lam wrote:

> The destructor uses delete thing;, not delete[] thing. Is that incorrect,
> then? (I usually program in languages with garbage collection...)

For char[], delete and delete[] do the same thing on most
implementations. However, it makes a huge difference when the objects
in the array have dtors.
"delete thing;" runs the dtor for 1 object. "delete[] thing;" runs the
dtors for N objects (the runtime remembers the array size, or figures it
out from the malloc header). It is best to be in the habit of using the
correct form, even for char[]. For instance, with user defined storage
managements, "delete[]" calls operator delete[](), and "delete" calls
operator delete(). If C++ was a sane language, this would be checked at
compile time, but they *had* to emulate the C pointer/array equivalence.

-- 
Stuart D. Gathman <stuart@bmsi.com>
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - Mozart background
song for the Microsoft "Where do you want to go from here?" commercial.



This archive was generated by hypermail 2b25 : Fri Mar 30 2001 - 14:59:46 CST