Sla*_*lav 6 c++ valgrind boost-bind
为什么valgrind的DRD工具抱怨"线程加载冲突...大小为4":关于这样的代码:
void SomeFunction(const int& value)
{
boost::bind(..., value); /* <-- complaines on this line
with last backtrace function "new(int)" */
}
Run Code Online (Sandbox Code Playgroud)
boost :: bind()是否按引用或值存储值?
seh*_*ehe 14
按价值.1
但你可以通过ref复制它:
void SomeFunction(const int& value)
{
boost::bind(..., boost::ref(value));
boost::bind(..., boost::cref(value)); // by const ref
}
Run Code Online (Sandbox Code Playgroud)
1 http://www.boost.org/doc/libs/1_46_1/libs/bind/bind.html#Purpose
i的值的副本存储在函数对象中.boost :: ref和boost :: cref可用于使函数对象存储对象的引用,而不是副本:int i = 5;
bind(f,ref(i),_ 1);
bind(f,cref(42),_ 1);