简体   繁体   English

没有线程安全开销的QSharedPointer?

[英]QSharedPointer without the thread-safety overhead?

I need to use a QSharedPointer for the reference counting, but I'll use it in a single-thread application so I don't want the thread-safety overhead (which I assume is fairly expensive). 我需要使用QSharedPointer进行引用计数,但我会在单线程应用程序中使用它,所以我不想要线程安全开销(我认为这是相当昂贵的)。

Is there a way to turn off the thread-safety, or is there an equivalent Qt class that offers reference-counting only? 有没有办法关闭线程安全性,还是有一个等效的Qt类只提供引用计数? If not, are there stand-alone classes that don't require me to include a big library like boost, or turn on c++11? 如果没有,是否有独立的课程,不要求我包括像boost这样的大型库,或打开c ++ 11?

Qt 5 has very clever realization of class QMutex . Qt 5 非常巧妙地实现了QMutex类 And it must not to use Synchronization Primitives of OS in a single-thread applications. 并且不得在单线程应用程序中使用OS的同步基元。 So, I think that using of Qt's smart pointers is a good solution. 所以,我认为使用Qt的智能指针是一个很好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM