<small id='ki5f6'></small><noframes id='ki5f6'>

          <bdo id='ki5f6'></bdo><ul id='ki5f6'></ul>
        <legend id='ki5f6'><style id='ki5f6'><dir id='ki5f6'><q id='ki5f6'></q></dir></style></legend>
        <i id='ki5f6'><tr id='ki5f6'><dt id='ki5f6'><q id='ki5f6'><span id='ki5f6'><b id='ki5f6'><form id='ki5f6'><ins id='ki5f6'></ins><ul id='ki5f6'></ul><sub id='ki5f6'></sub></form><legend id='ki5f6'></legend><bdo id='ki5f6'><pre id='ki5f6'><center id='ki5f6'></center></pre></bdo></b><th id='ki5f6'></th></span></q></dt></tr></i><div id='ki5f6'><tfoot id='ki5f6'></tfoot><dl id='ki5f6'><fieldset id='ki5f6'></fieldset></dl></div>
      1. <tfoot id='ki5f6'></tfoot>
      2. 在处理易失性内存位置时,编译器必须遵循哪些

        时间:2023-09-15
        <i id='jVaqf'><tr id='jVaqf'><dt id='jVaqf'><q id='jVaqf'><span id='jVaqf'><b id='jVaqf'><form id='jVaqf'><ins id='jVaqf'></ins><ul id='jVaqf'></ul><sub id='jVaqf'></sub></form><legend id='jVaqf'></legend><bdo id='jVaqf'><pre id='jVaqf'><center id='jVaqf'></center></pre></bdo></b><th id='jVaqf'></th></span></q></dt></tr></i><div id='jVaqf'><tfoot id='jVaqf'></tfoot><dl id='jVaqf'><fieldset id='jVaqf'></fieldset></dl></div>

          <tbody id='jVaqf'></tbody>
          <tfoot id='jVaqf'></tfoot>
            <bdo id='jVaqf'></bdo><ul id='jVaqf'></ul>

                <small id='jVaqf'></small><noframes id='jVaqf'>

                • <legend id='jVaqf'><style id='jVaqf'><dir id='jVaqf'><q id='jVaqf'></q></dir></style></legend>
                • 本文介绍了在处理易失性内存位置时,编译器必须遵循哪些规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我知道从多个线程或进程写入的内存位置读取时,volatile 关键字应该用于该位置,如下面的某些情况,但我想了解更多有关哪些限制的信息它真的对编译器有用吗?基本上编译器在处理这种情况时必须遵循什么规则,是否有任何例外情况,尽管同时访问内存位置,但程序员可以忽略 volatile 关键字.

                  I know when reading from a location of memory which is written to by several threads or processes the volatile keyword should be used for that location like some cases below but I want to know more about what restrictions does it really make for compiler and basically what rules does compiler have to follow when dealing with such case and is there any exceptional case where despite simultaneous access to a memory location the volatile keyword can be ignored by programmer.

                  volatile SomeType * ptr = someAddress;
                  void someFunc(volatile const SomeType & input){
                   //function body
                  }
                  

                  推荐答案

                  volatile 排除的一个特殊且非常常见的优化是将值从内存缓存到寄存器中,并使用注册重复访问(因为这比每次都返回内存要快得多).

                  A particular and very common optimization that is ruled out by volatile is to cache a value from memory into a register, and use the register for repeated access (because this is much faster than going back to memory every time).

                  相反,编译器必须每次都从内存中获取值(从 Zach 那里得到提示,我应该说每次"都受序列点的限制).

                  Instead the compiler must fetch the value from memory every time (taking a hint from Zach, I should say that "every time" is bounded by sequence points).

                  写入序列也不能使用寄存器并且稍后只将最终值写回:每次写入必须被推送到内存中.

                  Nor can a sequence of writes make use of a register and only write the final value back later on: every write must be pushed out to memory.

                  为什么这很有用?在某些架构上,某些 IO 设备将它们的输入或输出映射到内存位置(即写入该位置的字节实际上在串行线上输出).如果编译器将其中一些写入重定向到一个仅偶尔刷新的寄存器,那么大部分字节不会进入串行线路.不好.使用 volatile 可以防止这种情况.

                  Why is this useful? On some architectures certain IO devices map their inputs or outputs to a memory location (i.e. a byte written to that location actually goes out on the serial line). If the compiler redirects some of those writes to a register that is only flushed occasionally then most of the bytes won't go onto the serial line. Not good. Using volatile prevents this situation.

                  这篇关于在处理易失性内存位置时,编译器必须遵循哪些规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何确定返回的指针是在堆栈还是堆上 下一篇:如何忽略来自 _CrtDumpMemoryLeaks 的误报内存泄漏?

                  相关文章

                  最新文章

                  1. <i id='InCQe'><tr id='InCQe'><dt id='InCQe'><q id='InCQe'><span id='InCQe'><b id='InCQe'><form id='InCQe'><ins id='InCQe'></ins><ul id='InCQe'></ul><sub id='InCQe'></sub></form><legend id='InCQe'></legend><bdo id='InCQe'><pre id='InCQe'><center id='InCQe'></center></pre></bdo></b><th id='InCQe'></th></span></q></dt></tr></i><div id='InCQe'><tfoot id='InCQe'></tfoot><dl id='InCQe'><fieldset id='InCQe'></fieldset></dl></div>
                  2. <tfoot id='InCQe'></tfoot>
                  3. <small id='InCQe'></small><noframes id='InCQe'>

                    • <bdo id='InCQe'></bdo><ul id='InCQe'></ul>
                      <legend id='InCQe'><style id='InCQe'><dir id='InCQe'><q id='InCQe'></q></dir></style></legend>