Skip to Content

О семантике C++ (продолжение)

Наши читатели подсказывают нам, что в рассмотренном ранее примере может быть алиасинг.

Действительно, если у нас такое вот:

  1. class someShit{
  2.         char *m_sBuffer;
  3.         size_t m_iLimit;
  4.         size_t m_iCounter;
  5. };
то никто не может гарантировать, что где-то не написали:
  1.  m_sBuffer = (char*)&m_iCounter;
И тогда даже в одном треде можно огрести полные штаны счастья.

Меняю объявление на такое:

  1. class someShit{
  2.         char m_sBuffer[10240];
  3.         size_t m_iLimit;
  4.         size_t m_iCounter;
  5. };
И для интеловского компилятора получаю счастье, в данном примере в память лишний раз никто не лазит:
  1. void someShit::try1()
  2. {
  3.         m_iCounter = 0;
  4.         while (m_iCounter< m_iLimit && m_sBuffer[m_iCounter])
  5.                 m_iCounter++;
  6. }
MSVC 2010 это, правда, не помогло. Так и ходит через память.

Исходный вопрос (как отключить) снимается, restrict/__restrict в помощь, ключи компиляции опять-же есть.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <s> <i> <b> <blockquote>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Images can be added to this post.

More information about formatting options



.