C + + byte alignment

Source: Internet
Author: User

Reference url:http://blog.csdn.net/hairetz/article/details/4084088

0 byte justification As I understand it, it's easy for the CPU to take all the data at once and improve the execution of the code.

1-byte alignment rules

(1) The first member of the struct is offset as 0, and each subsequent member stores the starting position from which the member size (original type), or the member's Child member size (array), or the integer multiple address of the maximum child member size in the member is stored

(2) The total size of the struct, which is the result of sizeof, must be an integer multiple of its internal maximum member. Not enough to be done.

The following is the memory distribution in the Win7 x86_64 vs2015 x64 mode compilation mode

Variable b

Variable A

2 vs2015 such as compiler default is #pragma pack (8), so test our rules will be normal; GCC defaults to #pragma pack (4), and GCC only supports 1,2,4 alignment. The alignment value calculated in the above rule cannot be greater than the n value specified by the #pragma pack

  

C + + byte alignment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.