home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11209 < prev    next >
Encoding:
Internet Message Format  |  1992-07-20  |  1.6 KB

  1. Path: sparky!uunet!mcsun!corton!seti!goudurix.inria.fr!edelson
  2. From: daniel.edelson@inria.fr (Daniel R. Edelson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: delete versus delete[] (was Re: leakmeister)
  5. Message-ID: <4009@seti.UUCP>
  6. Date: 21 Jul 92 08:18:49 GMT
  7. References: <l6hmegINNfva@male.EBay.Sun.COM> <1992Jul18.200210.4119@taumet.com> <1992Jul19.162429.4307@usenet.ins.cwru.edu>
  8. Sender: news@seti.UUCP
  9. Reply-To: Daniel R. Edelson <daniel.edelson@inria.fr>
  10. Organization: INRIA -- Institut National de Recherche en Informatique et Automatique -- Rocquencourt, France
  11. Lines: 21
  12.  
  13. In article <1992Jul19.162429.4307@usenet.ins.cwru.edu>, aa753@cleveland.Freenet.Edu (Bob Jarvis) writes:
  14. |> 
  15. |> This should work correctly.  The only time that the 'delete []' syntax is
  16. |> required is if you have a dynamically-allocated array of class instances
  17. |> which have a destructor you want to have invoked for each class instance
  18. |> in the array.  
  19.  
  20. Nonetheless, the effect of deleting an array with the plain delete syntax
  21. is undefined. The definition of such "undefined behavior" is "an error that
  22. the compiler is not required to diagnose." 
  23.  
  24. It is not difficult to think of times when this can
  25. lead to problems, even for a class that doesn't have a
  26. destructor. Suppose that the class overloads new and
  27. delete to use a customized memory allocator. Allocating
  28. the array with `new T [x]' will call the global operator
  29. new and obtain memory from the standard place, whereas 
  30. deleting it without the array syntax will return the memory
  31. to the custom allocator. This is not what you want to happen.
  32.  
  33. daniel.edelson@inria.fr
  34.