Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

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

, 1 Oct 2010
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...

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
Italy Italy
No Biography provided

| | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 1 Oct 2010
Article Copyright 2010 by Sauro Viti
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid