Optimization/clarity coding : what is gcc able to do for me ?
jlh
jlh@gmx.ch
Sat Jan 15 21:22:00 GMT 2005
Nick NoSpam wrote:
> So since one thread is reading (size() is a const method), and another may
> be writing (perhaps adding new elements), it's fine for such implementations.
Only if you can ensure both operation to not happen at the same time. If you
call size() while another thread is just resizing the vector, you might get
wrong results.
> The compiler can't optimize away a function call if it doesn't know if the
> return value (or side effects) will be the same, right?
Correct. But for telling whether it may optimize away the call, the optimizer
will assume there's no other thread manipulating the same vector. (If that
wouldn't be, it would hardly be possible to optimize anything.) It's up to
you to make sure this assumption holds true in every situation.
jlh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20050115/025ebd0b/attachment.sig>
More information about the Gcc
mailing list