Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Why does valgrind's DRD tool complaines "Conflicting load by thread ... at size 4": about such code:

void SomeFunction(const int& value)
{
    boost::bind(..., value); /* <-- complaines on this line
                                with last backtrace function "new(int)" */
}

Does boost::bind() stores values by reference or value?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
556 views
Welcome To Ask or Share your Answers For Others

1 Answer

By value. 1

But you can make it copy by ref instead:

void SomeFunction(const int& value)
{
    boost::bind(..., boost::ref(value)); 
    boost::bind(..., boost::cref(value)); // by const ref
}

1 http://www.boost.org/doc/libs/1_46_1/libs/bind/bind.html#Purpose

a copy of the value of i is stored into the function object. boost::ref and boost::cref can be used to make the function object store a reference to an object, rather than a copy: int i = 5;

bind(f, ref(i), _1);

bind(f, cref(42), _1);


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...