<legend id='V5eXJ'><style id='V5eXJ'><dir id='V5eXJ'><q id='V5eXJ'></q></dir></style></legend>
<tfoot id='V5eXJ'></tfoot>

    <bdo id='V5eXJ'></bdo><ul id='V5eXJ'></ul>

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

  • <i id='V5eXJ'><tr id='V5eXJ'><dt id='V5eXJ'><q id='V5eXJ'><span id='V5eXJ'><b id='V5eXJ'><form id='V5eXJ'><ins id='V5eXJ'></ins><ul id='V5eXJ'></ul><sub id='V5eXJ'></sub></form><legend id='V5eXJ'></legend><bdo id='V5eXJ'><pre id='V5eXJ'><center id='V5eXJ'></center></pre></bdo></b><th id='V5eXJ'></th></span></q></dt></tr></i><div id='V5eXJ'><tfoot id='V5eXJ'></tfoot><dl id='V5eXJ'><fieldset id='V5eXJ'></fieldset></dl></div>

        __attribute__((packed)) 会影响程序的性能吗?

        时间:2023-06-04

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

          • <bdo id='OghRU'></bdo><ul id='OghRU'></ul>
            <legend id='OghRU'><style id='OghRU'><dir id='OghRU'><q id='OghRU'></q></dir></style></legend>
                <tbody id='OghRU'></tbody>
              1. <tfoot id='OghRU'></tfoot>
                  本文介绍了__attribute__((packed)) 会影响程序的性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个名为 log 的结构,其中有 13 个字符.做了一个sizeof(log)后发现大小不是13而是16.我可以用__attribute__((packed))把它变成13的实际大小,但是我想知道这是否会影响程序的性能.这是一个使用频率很高的结构.

                  I have a structure called log that has 13 chars in it. after doing a sizeof(log) I see that the size is not 13 but 16. I can use the __attribute__((packed)) to get it to the actual size of 13 but I wonder if this will affect the performance of the program. It is a structure that is used quite frequently.

                  我希望能够读取结构的大小(13 不是 16).我可以使用宏,但如果此结构发生更改,即添加或删除字段,我希望在不更改宏的情况下更新新大小,因为我认为这很容易出错.有什么建议吗?

                  I would like to be able to read the size of the structure (13 not 16). I could use a macro, but if this structure is ever changed ie fields added or removed, I would like the new size to be updated without changing a macro because I think this is error prone. Have any suggestion?

                  推荐答案

                  是的,会影响程序的性能.添加填充意味着编译器可以使用整数加载指令从内存中读取内容.如果没有填充,编译器必须单独加载内容并进行位移以获得整个值.(即使是 x86 并且这是由硬件完成的,它仍然必须完成).

                  Yes, it will affect the performance of the program. Adding the padding means the compiler can use integer load instructions to read things from memory. Without the padding, the compiler must load things separately and do bit shifting to get the entire value. (Even if it's x86 and this is done by the hardware, it still has to be done).

                  考虑一下:如果不是出于性能原因,编译器为什么会插入随机的、未使用的空间?

                  Consider this: Why would compilers insert random, unused space if it was not for performance reasons?

                  这篇关于__attribute__((packed)) 会影响程序的性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:无法理解 LARGE_INTEGER 结构 下一篇:STL设置了什么样的树实现?

                  相关文章

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

                  <i id='YQ6OX'><tr id='YQ6OX'><dt id='YQ6OX'><q id='YQ6OX'><span id='YQ6OX'><b id='YQ6OX'><form id='YQ6OX'><ins id='YQ6OX'></ins><ul id='YQ6OX'></ul><sub id='YQ6OX'></sub></form><legend id='YQ6OX'></legend><bdo id='YQ6OX'><pre id='YQ6OX'><center id='YQ6OX'></center></pre></bdo></b><th id='YQ6OX'></th></span></q></dt></tr></i><div id='YQ6OX'><tfoot id='YQ6OX'></tfoot><dl id='YQ6OX'><fieldset id='YQ6OX'></fieldset></dl></div>

                  <tfoot id='YQ6OX'></tfoot>

                    • <bdo id='YQ6OX'></bdo><ul id='YQ6OX'></ul>
                    1. <legend id='YQ6OX'><style id='YQ6OX'><dir id='YQ6OX'><q id='YQ6OX'></q></dir></style></legend>