Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/memory/polymorphic allocator/deallocate object"

From cppreference.com
m (fmt, {{c}}, .)
m (See also)
 
(One intermediate revision by one user not shown)
Line 3: Line 3:
  
 
{{ddcl|since=c++20|1=  
 
{{ddcl|since=c++20|1=  
template<class U>
+
template< class U >
 
void deallocate_object( U* p, std::size_t n = 1 );
 
void deallocate_object( U* p, std::size_t n = 1 );
 
}}
 
}}
  
Deallocates the storage pointed to by {{c|p}}, which must have been allocated from a {{lc|std::pmr::memory_resource}} {{c|x}} that compares equal to {{c|*resource()}}, using {{c|x.allocate(n*sizeof(U), alignof(U))}}, typically through a call to {{c|allocate_object<U>(n)}}.
+
Deallocates the storage pointed to by {{c|p}}, which must have been allocated from a {{lc|std::pmr::memory_resource}} {{c|x}} that compares equal to {{c|*resource()}}, using {{c|x.allocate(n * sizeof(U), alignof(U))}}, typically through a call to {{c|allocate_object<U>(n)}}.
  
Equivalent to {{c|deallocate_bytes(p, n*sizeof(U), alignof(U));}}.
+
Equivalent to {{c|deallocate_bytes(p, n * sizeof(U), alignof(U));}}.
  
 
===Parameters===
 
===Parameters===
Line 31: Line 31:
 
{{dsc end}}
 
{{dsc end}}
  
{{langlinks|es|ja|zh}}
+
{{langlinks|es|ja|ru|zh}}

Latest revision as of 02:10, 19 July 2023

 
 
Dynamic memory management
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Allocators
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)



 
 
template< class U >
void deallocate_object( U* p, std::size_t n = 1 );
(since C++20)

Deallocates the storage pointed to by p, which must have been allocated from a std::pmr::memory_resource x that compares equal to *resource(), using x.allocate(n * sizeof(U), alignof(U)), typically through a call to allocate_object<U>(n).

Equivalent to deallocate_bytes(p, n * sizeof(U), alignof(U));.

Contents

[edit] Parameters

p - pointer to memory to deallocate
n - number of objects of type U the memory was for

[edit] Exceptions

Throws nothing.

[edit] Notes

This function was introduced for use with the fully-specialized allocator std::pmr::polymorphic_allocator<>, but it may be useful in any specialization.

[edit] See also

free raw memory obtained from allocate_bytes
(public member function) [edit]
destroys and deallocates an object
(public member function) [edit]
[static]
deallocates storage using the allocator
(public static member function of std::allocator_traits<Alloc>) [edit]
deallocates memory
(public member function of std::pmr::memory_resource) [edit]