Dynamic memory management

From cppreference.com
< cpp
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)
 
Dynamic memory management
Smart pointers
(C++11)
(C++11)
(C++11)
(until C++17)
(C++11)
(C++23)
Allocators
Memory resources
Uninitialized storage
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Garbage collection support
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
Miscellaneous
(C++20)
(C++11)
(C++11)
 

Smart pointers

Smart pointers enable automatic, exception-safe, object lifetime management.

Defined in header <memory>
Pointer categories
smart pointer with unique object ownership semantics
(class template)
smart pointer with shared object ownership semantics
(class template)
(C++11)
weak reference to an object managed by std::shared_ptr
(class template)
(deprecated in C++11)(removed in C++17)
smart pointer with strict object ownership semantics
(class template)
Helper classes
provides mixed-type owner-based ordering of shared and weak pointers
(class template)
allows an object to create a shared_ptr referring to itself
(class template)
exception thrown when accessing a weak_ptr which refers to already destroyed object
(class)
default deleter for unique_ptr
(class template)
Smart pointer adaptors
(C++23)
interoperates with foreign pointer setters and resets a smart pointer on destruction
(class template)
(C++23)
creates an out_ptr_t with an associated smart pointer and resetting arguments
(function template)
interoperates with foreign pointer setters, obtains the initial pointer value from a smart pointer, and resets it on destruction
(class template)
(C++23)
creates an inout_ptr_t with an associated smart pointer and resetting arguments
(function template)

Allocators

Allocators are class templates encapsulating memory allocation strategy. This allows generic containers to decouple memory management from the data itself.

Defined in header <memory>
the default allocator
(class template)
provides information about allocator types
(class template)
records the address and the actual size of storage allocated by allocate_at_least
(class template)
allocates storage at least as large as the requested size via an allocator
(function template)
an object of type std::allocator_arg_t used to select allocator-aware constructors
(constant)
checks if the specified type supports uses-allocator construction
(class template)
prepares the argument list matching the flavor of uses-allocator construction required by the given type
(function template)
creates an object of the given type by means of uses-allocator construction
(function template)
creates an object of the given type at specified memory location by means of uses-allocator construction
(function template)
Defined in header <scoped_allocator>
implements multi-level allocator for multi-level containers
(class template)
Defined in header <memory_resource>
Defined in namespace std::pmr
an allocator that supports run-time polymorphism based on the std::memory_resource it is constructed with
(class template)

Memory resources

Memory resources implement memory allocation strategies that can be used by std::pmr::polymorphic_allocator

Defined in header <memory_resource>
Defined in namespace std::pmr
an abstract interface for classes that encapsulate memory resources
(class)
returns a static program-wide std::pmr::memory_resource that uses the global operator new and operator delete to allocate and deallocate memory
(function)
returns a static std::pmr::memory_resource that performs no allocation
(function)
gets the default std::pmr::memory_resource
(function)
sets the default std::pmr::memory_resource
(function)
a set of constructor options for pool resources
(class)
a thread-safe std::pmr::memory_resource for managing allocations in pools of different block sizes
(class)
a thread-unsafe std::pmr::memory_resource for managing allocations in pools of different block sizes
(class)
a special-purpose std::pmr::memory_resource that releases the allocated memory only when the resource is destroyed
(class)

Uninitialized storage

Several utilities are provided to create and access raw storage.

Defined in header <memory>
(deprecated in C++17)(removed in C++20)
an iterator that allows standard algorithms to store results in uninitialized memory
(class template)
(deprecated in C++17)(removed in C++20)
obtains uninitialized storage
(function template)
(deprecated in C++17)(removed in C++20)
frees uninitialized storage
(function template)

Uninitialized memory algorithms

Defined in header <memory>
copies a range of objects to an uninitialized area of memory
(function template)
copies a number of objects to an uninitialized area of memory
(function template)
copies an object to an uninitialized area of memory, defined by a range
(function template)
copies an object to an uninitialized area of memory, defined by a start and a count
(function template)
moves a range of objects to an uninitialized area of memory
(function template)
moves a number of objects to an uninitialized area of memory
(function template)
constructs objects by default-initialization in an uninitialized area of memory, defined by a range
(function template)
constructs objects by default-initialization in an uninitialized area of memory, defined by a start and a count
(function template)
constructs objects by value-initialization in an uninitialized area of memory, defined by a range
(function template)
constructs objects by value-initialization in an uninitialized area of memory, defined by a start and a count
(function template)
destroys an object at a given address
(function template)
(C++17)
destroys a range of objects
(function template)
(C++17)
destroys a number of objects in a range
(function template)
creates an object at a given address
(function template)

Constrained uninitialized memory algorithms (C++20)

C++20 provides constrained uninitialized memory algorithms that accept range arguments or iterator-sentinel pairs.

Defined in header <memory>
Defined in namespace std::ranges
Specifies some operations on iterators, sentinels and ranges are non-throwing
(exposition-only concept)
copies a range of objects to an uninitialized area of memory
(niebloid)
copies a number of objects to an uninitialized area of memory
(niebloid)
copies an object to an uninitialized area of memory, defined by a range
(niebloid)
copies an object to an uninitialized area of memory, defined by a start and a count
(niebloid)
moves a range of objects to an uninitialized area of memory
(niebloid)
moves a number of objects to an uninitialized area of memory
(niebloid)
constructs objects by default-initialization in an uninitialized area of memory, defined by a range
(niebloid)
constructs objects by default-initialization in an uninitialized area of memory, defined by a start and count
(niebloid)
constructs objects by value-initialization in an uninitialized area of memory, defined by a range
(niebloid)
constructs objects by value-initialization in an uninitialized area of memory, defined by a start and a count
(niebloid)
destroys an object at a given address
(niebloid)
destroys a range of objects
(niebloid)
destroys a number of objects in a range
(niebloid)
creates an object at a given address
(niebloid)

Garbage collector support

Defined in header <memory>
(C++11)(removed in C++23)
declares that an object can not be recycled
(function)
(C++11)(removed in C++23)
declares that an object can be recycled
(function template)
(C++11)(removed in C++23)
declares that a memory area does not contain traceable pointers
(function)
(C++11)(removed in C++23)
cancels the effect of std::declare_no_pointers
(function)
(C++11)(removed in C++23)
lists pointer safety models
(enum)
(C++11)(removed in C++23)
returns the current pointer safety model
(function)

Miscellaneous

Defined in header <memory>
provides information about pointer-like types
(class template)
obtains a raw pointer from a pointer-like type
(function template)
(C++11)
obtains actual address of an object, even if the & operator is overloaded
(function template)
(C++11)
aligns a pointer in a buffer
(function)
informs the compiler that a pointer is aligned
(function template)

C-style memory management

Includes e.g. std::malloc, std::free

Low level memory management

Includes e.g. operator new, operator delete, std::set_new_handler