Click here to Skip to main content
12,450,347 members (51,004 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

5.6K views
1 bookmarked
Posted

C++ Tip: Aware of the confusion between delete with delete[]

, 1 Oct 2010 CPOL
The C++ comes with a rich standard library: the STL (Standard Template Library).So, why we should re-invent the wheel while we already have it done, safe and written to be light-weighed and performant?It's too much better to use the vector Class (Standard C++ Library)[^]:#include...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

31 Aug 2010
MilesAhead
A good exercise to aid in always using delete [] where appropriate is to code your own autoarray_ptr following the pattern of c++ auto_ptr. The destructor calls delete [] when the instance goes out of scope. Saves writing a lot of messy delete [] code in "if chains" and switch blocks....
13 Aug 2011
BWake
It is a bad idea to treat built-in types differently than programmer defined classes. If you delete a dynamically allocated array of a built-in type without the brackets the memory buffer may go away just fine. This is not guaranteed. The VS2008 runtime throws an exception. There is a...
31 Aug 2010
elitehussar
3 alternatives  

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sauro Viti
Engineer Cutlite Penta S.r.l.
Italy Italy
No Biography provided

Pro
Pro
| | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 1 Oct 2010
Article Copyright 2010 by Sauro Viti
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid