常量提升的目的:: shared_ptr的< T>&安培;作为函数的参数? [英] Purpose of const boost::shared_ptr<T>& as function argument?

查看:229
本文介绍了常量提升的目的:: shared_ptr的< T>&安培;作为函数的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是某些大型和维护良好的开源C ++库并在具有形式的构造一类定义来

I'm using a certain large and well-maintained open-source C++ library and came across a class definition having a constructor of the form

class SomeClass {
    SomeClass( const boost::shared_ptr<SomeOtherClass>& );
}

我的问题是:什么是传递一个常量的boost :: shared_ptr的&LT点; T&GT; 引用?是否真的有过一个的boost :: shared_ptr的与相关联的开销不可忽略的量; T&GT; 通过值,或者是有一些其他类型的危险传递的boost :: shared_ptr的&LT; T&GT; 按值,我不知道的。

My question is: what's the point of passing a const boost::shared_ptr<T> by reference? Is there really a non-negligible amount of overhead associated with passing a boost::shared_ptr<T> by value, or is there some other kind of danger to passing a boost::shared_ptr<T> by value that I'm not aware of?

推荐答案

按值传递这是要复制它导致一个引用计数增加,所有线程同步。绝对不可忽略的。

Passing this by value is going to copy it which results in a reference count increment, synchronized across all threads. Definitely non-negligible.

这篇关于常量提升的目的:: shared_ptr的&LT; T&GT;&安培;作为函数的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆