Learning about the memory layout of C + + objects under win x64

Source: Internet
Author: User

This article is a study note on the next situation of x64 after learning Chenhao's article, "Memory layout of C + + objects (top)". The link address of his article is: http://blog.csdn.net/haoel/article/details/3081328.

His sample code has the following fragments:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/88/58/wKiom1fweyigwHs2AAAMcXncBAA543.png-wh_500x0-wm_3 -wmp_4-s_1224092324.png "title=" 1.png "alt=" Wkiom1fweyigwhs2aaamcxncbaa543.png-wh_50 "/>

If you compile the x64 version of EXE in VS2015 Community Edition as debug, it crashes. After debugging, it is found that the address under x64 is represented by unsigned long long (if the test finds that the compilation background actually converts unsigned long long to unsigned __int64).

This code needs to be modified slightly to compile the normal x64 version of EXE:

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/88/58/wKiom1fwfJ2j4m_mAAA5fvc_lAc034.png-wh_500x0-wm_3 -wmp_4-s_746272943.png "title=" 2.png "alt=" Wkiom1fwfj2j4m_maaa5fvc_lac034.png-wh_50 "/>

The results of the post-compilation run are the results of the original post program output:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/88/54/wKioL1fwfQnRFdQ5AAAWnOOnZio131.png-wh_500x0-wm_3 -wmp_4-s_1847209560.png "title=" 3.png "alt=" Wkiol1fwfqnrfdq5aaawnoonzio131.png-wh_50 "/>


From this learning debugging process, you can find that in x64 int, long two data types are used 4bytes storage. I always thought that under the x64 long type would occupy 8bytes, &GC cast to unsigned long**, the compiled program is always not normal. It is only normal to use unsigned long long**.

This article is from the "Hidden Forest Road" blog, please be sure to keep this source http://wxinhe.blog.51cto.com/6924993/1858369

Learning about the memory layout of C + + objects under win x64

Related Article

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.