Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr as reference argument
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2009-03-20 16:50:58

On Fri, Mar 20, 2009 at 5:00 PM, Steven Watanabe <watanabesj_at_[hidden]>wrote:

> const might also involve some optimizations, e.g. in multi-threaded
>> context.
>> Let's imagine a value being passed to a function by const reference. This
>> function starts 2 or more threads and passes the value to them as
>> reference
>> to a const object as well. What happens in this context? As long it is not
>> volatile it might be cached in a register, but I think that if the value
>> is
>> const, compiler has stronger assumption, that this value is good enough to
>> be cached for all threads...
> If you have a reference to const, the compiler cannot make
> any assumptions about whether it is modified or not, because
> of const_cast. Objects declared const are another matter,
> because it is undefined behavior to modify them.

Ok, I don't want to stick on this. In my initial post, I wrote that const
provides a compiler an additional information which !!!might!!! be used
usefully for optimization (!!!big doubt!!!). Emil writes that this info for
sure is neglected, but I still don't think so.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at