Question about C # [structlayout (layoutkind. Sequential )]

Source: Internet
Author: User

Struct is composed of several members. There are two types of layout:

1. Sequential: sequential layout, such

Struct S1 {

Int;

Int B ;}

By default, A is first arranged in the memory, and then B is arranged. That is, if the address of a and the address of B can be obtained,

The difference is the length of an int type, 4 bytes

[Structlayout (layoutkind. Sequential)]

Struct S1 {

Int;

Int B ;}

This is the same as the previous one, because the default memory arrangement is sequential, that is, sequential arrangement by members.

2. explicit, exact layout requires fieldoffset ()

Set the location of each Member to implement the C-like public body function.

[Structlayout (layoutkind. explicit)]

Struct S1 {

[Fieldoffset (0)]

Int;

[Fieldoffset (0)]

Int B ;}

In this way, A and B are in the same memory address.

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.