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

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

    1. <tfoot id='vc9Yq'></tfoot>

      1. <legend id='vc9Yq'><style id='vc9Yq'><dir id='vc9Yq'><q id='vc9Yq'></q></dir></style></legend>

        • <bdo id='vc9Yq'></bdo><ul id='vc9Yq'></ul>

        c++11 中的类型什么时候可以被 memcpyed?

        时间:2023-09-17

      2. <tfoot id='7HEia'></tfoot>

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

                  <small id='7HEia'></small><noframes id='7HEia'>

                  <legend id='7HEia'><style id='7HEia'><dir id='7HEia'><q id='7HEia'></q></dir></style></legend>
                    <tbody id='7HEia'></tbody>
                1. 本文介绍了c++11 中的类型什么时候可以被 memcpyed?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的问题如下:

                  如果我想复制一个类类型,memcpy 可以非常快地完成.这在某些情况下是允许的.

                  If I want to copy a class type, memcpy can do it very fast. This is allowed in some situations.

                  我们有一些类型特征:

                  • is_standard_layout.
                  • is_trivially_copyable.

                  我想知道的是当一个类型可以按位复制"时的确切要求.

                  What I would like to know is the exact requirements when a type will be "bitwise copyable".

                  我的结论是,如果 is_trivally_copyableis_standard_layout 特征都为真,则类型是可按位复制的:

                  My conclusion is that a type is bitwise copyable if both of is_trivally_copyable and is_standard_layout traits are true:

                  1. 这正是我需要按位复制的内容吗?
                  2. 是否过度约束?
                  3. 是否受到限制?

                  P.S.:当然,memcpy 的结果一定是正确的.我知道我可以在任何情况下进行 memcpy,但不正确.

                  P.S.: of course, the result of memcpy must be correct. I know I could memcpy in any situation but incorrectly.

                  推荐答案

                  is_trivially_copyable::value 是真的.没有特别需要该类型是标准布局类型.可简单复制"的定义本质上是这样做是安全的.

                  You can copy an object of type T using memcpy when is_trivially_copyable<T>::value is true. There is no particular need for the type to be a standard layout type. The definition of 'trivially copyable' is essentially that it's safe to do this.

                  使用 memcpy 可以安全复制但不是标准布局的类示例:

                  An example of a class that is safe to copy with memcpy but which is not standard layout:

                  struct T {
                    int i;
                  private:
                    int j;
                  };
                  

                  因为这个类对不同的非静态数据成员使用不同的访问控制,所以不是标准布局,但它仍然可以简单地复制.

                  Because this class uses different access control for different non-static data members it is not standard layout, but it is still trivially copyable.

                  这篇关于c++11 中的类型什么时候可以被 memcpyed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我如何估计 std::map 的内存使用量? 下一篇:我如何称呼原始的“运营商新"?如果我超载了

                  相关文章

                  最新文章

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

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

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