单例模式和 std::unique_ptr [英] singleton pattern and std::unique_ptr
本文介绍了单例模式和 std::unique_ptr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
std::unique_ptr
唯一地控制它指向的对象,因此不使用引用计数.单例确保只能使用引用计数创建一个对象.
std::unique_ptr
uniquely controls the object it points to and, hence, does not utilize reference counting. A singleton ensures only one object may be created utilizing reference counting.
那么 std::unique_ptr
的性能是否与单例相同?
Would then std::unique_ptr
perform identically to a singleton?
推荐答案
单例确保只有一个类型的实例.
unique_ptr
确保只有一个智能指针指向任何实例.
这篇关于单例模式和 std::unique_ptr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文