##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# Dynamic memory management

From cppreference.com
< cpp

### [edit] Smart pointers

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

Defined in header `<memory>`
##### Pointer categories
unique_ptr (C++11) | smart pointer with unique object ownership semantics (class template) [edit]
shared_ptr (C++11) | smart pointer with shared object ownership semantics (class template) [edit]
weak_ptr (C++11) | weak reference to an object managed by std::shared_ptr (class template) [edit]
auto_ptr (until C++17) | smart pointer with strict object ownership semantics (class template) [edit]
##### Helper classes
owner_less (C++11) | provides mixed-type owner-based ordering of shared and weak pointers (class template) [edit]
enable_shared_from_this (C++11) | allows an object to create a `shared_ptr` referring to itself (class template) [edit]
bad_weak_ptr (C++11) | exception thrown when accessing a `weak_ptr` which refers to already destroyed object (class) [edit]
default_delete (C++11) | default deleter for `unique_ptr` (class template) [edit]

### [edit] 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>`
allocator | the default allocator (class template) [edit]
allocator_traits (C++11) | provides information about allocator types (class template) [edit]
allocator_arg_t (C++11) | tag type used to select allocator-aware constructor overloads (class) [edit]
allocator_arg (C++11) | an object of type std::allocator_arg_t used to select allocator-aware constructors (constant) [edit]
uses_allocator (C++11) | checks if the specified type supports uses-allocator construction (class template) [edit]
Defined in header `<scoped_allocator>`
scoped_allocator_adaptor (C++11) | implements multi-level allocator for multi-level containers (class template) [edit]
Defined in header `<memory_resource>`
Defined in namespace `pmr`
polymorphic_allocator (C++17) | an allocator that supports run-time polymorphism based on the std::memory_resource it is constructed with (class template) [edit]

### [edit] 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 `pmr`
memory_resource (C++17) | an abstract interface for classes that encapsulate memory resources (class) [edit]
new_delete_resource (C++17) | returns a static program-wide std::pmr::memory_resource that uses the global operator new and operator delete to allocate and deallocate memory (function) [edit]
null_memory_resource (C++17) | returns a static std::pmr::memory_resource that performs no allocation (function) [edit]
get_default_resource (C++17) | gets the default std::pmr::memory_resource (function) [edit]
set_default_resource (C++17) | sets the default std::pmr::memory_resource (function) [edit]
pool_options (C++17) | a set of constructor options for pool resources (class) [edit]
synchronized_pool_resource (C++17) | a thread-safe std::pmr::memory_resource for managing allocations in pools of different block sizes (class) [edit]
unsynchronized_pool_resource (C++17) | a thread-unsafe std::pmr::memory_resource for managing allocations in pools of different block sizes (class) [edit]
monotonic_buffer_resource (C++17) | a special-purpose std::pmr::memory_resource that releases the allocated memory only when the resource is destroyed (class) [edit]

### [edit] Uninitialized storage

Several utilities are provided to create and access raw storage

Defined in header `<memory>`
uninitialized_copy | copies a range of objects to an uninitialized area of memory (function template) [edit]
uninitialized_copy_n (C++11) | copies a number of objects to an uninitialized area of memory (function template) [edit]
uninitialized_fill | copies an object to an uninitialized area of memory, defined by a range (function template) [edit]
uninitialized_fill_n | copies an object to an uninitialized area of memory, defined by a start and a count (function template) [edit]
uninitialized_move (C++17) | moves a range of objects to an uninitialized area of memory (function template) [edit]
uninitialized_move_n (C++17) | moves a number of objects to an uninitialized area of memory (function template) [edit]
uninitialized_default_construct (C++17) | constructs objects by default-initialization in an uninitialized area of memory, defined by a range (function template) [edit]
uninitialized_default_construct_n (C++17) | constructs objects by default-initialization in an uninitialized area of memory, defined by a start and a count (function template) [edit]
uninitialized_value_construct (C++17) | constructs objects by value-initialization in an uninitialized area of memory, defined by a range (function template) [edit]
uninitialized_value_construct_n (C++17) | constructs objects by value-initialization in an uninitialized area of memory, defined by a start and a count (function template) [edit]
destroy_at (C++17) | destroys an object at a given address (function template) [edit]
destroy (C++17) | destroys a range of objects (function template) [edit]
destroy_n (C++17) | destroys a number of objects in a range (function template) [edit]
raw_storage_iterator (deprecated in C++17) | an iterator that allows standard algorithms to store results in uninitialized memory (class template) [edit]
get_temporary_buffer (deprecated in C++17) | obtains uninitialized storage (function template) [edit]
return_temporary_buffer (deprecated in C++17) | frees uninitialized storage (function template) [edit]

### [edit] Garbage collector support

Defined in header `<memory>`
declare_reachable (C++11) | declares that an object can not be recycled (function) [edit]
undeclare_reachable (C++11) | declares that an object can be recycled (function template) [edit]
declare_no_pointers (C++11) | declares that a memory area does not contain traceable pointers (function) [edit]
undeclare_no_pointers (C++11) | cancels the effect of std::declare_no_pointers (function) [edit]
pointer_safety (C++11) | lists pointer safety models (class) [edit]
get_pointer_safety (C++11) | returns the current pointer safety model (function) [edit]

### [edit] Miscellaneous

Defined in header `<memory>`
pointer_traits (C++11) | provides information about pointer-like types (class template) [edit]
addressof (C++11) | obtains actual address of an object, even if the & operator is overloaded (function template) [edit]
align (C++11) | aligns a pointer in a buffer (function) [edit]

### [edit] C-style memory management

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

### [edit] Low level memory management

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

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/memory&oldid=86796"