C++ FAQ Celebrating Twenty-One Years of the C++ FAQ!!!
(Click here for a personal note from Marshall Cline.)
Contents - 40 sections.
12345678910111213141516171819202122232425262728293031323334353637383940 ]
About the Author.
Marshall Cline
Topical index - 5676 links to 3571 topics.
Search the C++ FAQ.
Recent changes - 11 changed FAQs.
In a list, or in a chain, or here: [4.1], [4.2], [6.3], [6.12], [10.3], [15.22], [27.15], [35.13], [35.14], [35.15], [39.6].
Mirrored in 11 countries.
USA, France, Germany, Ireland, Israel, Italy, Poland, Portugal, Spain, Taiwan, U.K..
[16] Freestore management
16.1 Does delete p delete the pointer p, or the pointed-to-data *p?
16.2 Is it safe to delete the same pointer twice?
16.3 Can I free() pointers allocated with new? Can I delete pointers allocated with malloc()?
16.4 Why should I use new instead of trustworthy old malloc()?
16.5 Can I use realloc() on pointers allocated via new?
16.6 Do I need to check for NULL after p = new Fred()?
16.7 How can I convince my (older) compiler to automatically check new to see if it returns NULL?
16.8 Do I need to check for NULL before delete p?
16.9 What are the two steps that happen when I say delete p?
16.10 In p = new Fred(), does the Fred memory "leak" if the Fred constructor throws an exception?
16.11 How do I allocate / unallocate an array of things?
16.12 What if I forget the [] when deleteing an array allocated via new T[n]?
16.13 Can I drop the [] when deleteing an array of some built-in type (char, int, etc)?
16.14 After p = new Fred[n], how does the compiler know there are n objects to be destructed during delete[] p?
16.15 Is it legal (and moral) for a member function to say delete this?
16.16 How do I allocate multidimensional arrays using new?
16.17 But the previous FAQ's code is SOOOO tricky and error prone! Isn't there a simpler way?
16.18 But the above Matrix class is specific to Fred! Isn't there a way to make it generic?
16.19 What's another way to build a Matrix template?
16.20 Does C++ have arrays whose length can be specified at run-time?
16.21 How can I force objects of my class to always be created via new rather than as locals or global/static objects?
16.22 How do I do simple reference counting?
16.23 How do I provide reference counting with copy-on-write semantics?
16.24 How do I provide reference counting with copy-on-write semantics for a hierarchy of classes?
16.25 Can I absolutely prevent people from subverting the reference counting mechanism, and if so, should I?
16.26 Can I use a garbage collector in C++?
16.27 What are the two kinds of garbage collectors for C++?
16.28 Where can I get more info on garbage collectors for C++?