“破坏” “析构函数” “解除分配”在std :: allocator? [英] Difference between "destroy" "destructor" "deallocate" in std::allocator?
问题描述
在C ++ std :: allocator
中,有三种与一个常见概念相关的方法:
-
deallocate
-
销毁
- 破坏器
我想知道:
- $
- b $ b
- >
谢谢!
编辑:更具体的疑问:
对不起,先归纳一下,以下是一些我不明白的观点。
- 析构函数做什么?文档没有讨论调用析构函数时是否自动释放内存
-
destroy
用于调用对象,这里的对象是什么意思?
再次感谢!
< div只是来自 cppreference.com文档为我解释这些差异非常清楚
1.析构函数是什么?关于当调用析构函数时是否会自动释放内存
<$ c $
再次引用详细文档
void destroy(pointer p); // 1)
template<类U> // 2)
void destroy(U * p);
调用p指向的对象的析构函数
1)调用((T *)p) - >〜T()
2)调用p - >〜U()
由
std :: allocator
实例管理的T
类型的对象。In C++
std::allocator
, there are three methods relating to a common concept:deallocate
destroy
- destructor
I want to know:
- How are they different from each other from the memory management perspective?
- when should I use this but not that?
Thank you!
Edit: More specific doubts:
I am sorry to generalize it at first, here are some points I don't understand.
- What does destructor do? The documentation didn't talk about whether the memory will be released automatically when the destructor is called
- The
destroy
is used to call the destructor on a object, what does the "object" here means?
Thank you again!
解决方案Just the brief descriptions from the cppreference.com documentation explain the differences very clearly for me
"1. What does destructor do? The documentation didn't talk about whether the memory will be released automatically when the destructor is called"
Any memory occupied by the
std::allocator
instance will be released as usual."2. The
destroy
is used to call the destructor on a object, what does the "object" here means?"Again to cite the detailed documentation
void destroy( pointer p ); // 1) template< class U > // 2) void destroy( U* p );
Calls the destructor of the object pointed to by p
1) Calls((T*)p)->~T()
2) Callsp->~U()
Object in this context means an object of type
T
managed by thestd::allocator
instance.这篇关于“破坏” “析构函数” “解除分配”在std :: allocator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!