Defined Terms
allocator Library class that allocates unconstructed memory.
dangling pointer A pointer that refers to memory that once had an object but no longer does. Program errors due to dangling pointers are notoriously difficult to debug.
delete Frees memory allocated by
new
.delete p
frees the object anddelete [] p
frees the array to whichp
points.p
may be null or point to memory allocated bynew
.deleter Function passed to a smart pointer to use in place of
delete
when destroying the object to which the pointer is bound.destructor Special member function that cleans up an object when the object goes out of scope or is deleted.
dynamically allocated Object that is allocated on the free store. Objects allocated on the free store exist until they are explicitly deleted or the program terminates.
free store Memory pool available to a program to hold dynamically allocated objects.
heap Synonym for free store.
new Allocates memory from the free store.
new T
allocates and constructs an object of typeT
and returns a pointer to that object; ifT
is an array type,new
returns a pointer to the first element in the array. Similarly,new [
allocates n objects of typeT
and returns a pointer to the first element in the array. By default, the allocated object is default initialized. We may also provide optional initializers.placement new Form of
new
that takes additional arguments passed in parentheses following the keywordnew
; for example,new (nothrow) int
tellsnew
that it should not throw an exception.reference count Counter that tracks how many users share a common object. Used by smart pointers to know when it is safe to delete memory to which the pointers point.
shared_ptr Smart pointer that provides shared ownership: The object is deleted when the last
shared_ptr
pointing to that object is destroyed.smart pointer Library type that acts like a pointer but can be checked to see whether it is safe to use. The type takes care of deleting memory when appropriate.
unique_ptr Smart pointer that provides single ownership: The object is deleted when the
unique_ptr
pointing to that object is destroyed.unique_ptr
s cannot be directly copied or assigned.weak_ptr Smart pointer that points to an object managed by a
shared_ptr
. Theshared_ptr
does not countweak_ptr
s when deciding whether to delete its object.