Re: Is delete dangerous, when delete[] is appropriate?
  Home FAQ Contact Sign in
comp.lang.c++.moderated only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Is delete dangerous, when delete[] is appropriate?         

Group: comp.lang.c++.moderated · Group Profile
Author: peter koch larsen
Date: Jul 10, 2007 08:39

On 10 Jul., 14:28, ted trhj.homeunix.net> wrote:
> If I use delete, when delete[] is correct, can the consequence be
> anything
> worse than a memory leak?

Yes. What happens is not specified, but typical behaviour includes
memory leaks, missing destructor calls, heap corruption and crash.
>
> E.g.
> int* pi = new int[2];
> delete pi; // delete[] is correct
>

There's practically never any reason to use new[]. Prefer using
std::vector which has very low overhead and offers additional safety
and lots of extra goodies such as resizing.

/Peter

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
no comments
diggit! del.icio.us! reddit!