[Structlayout (layoutkind. Sequential )]

Source: Internet
Author: User

[Structlayout (layoutkind. Sequential)] is a structure Sorting Problem;

First, we will introduce the differences between struct and classes: the class is passed by reference, and the struct is passed by value.

Enter the subject:

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.
That is, if you can get the address of a, and the address of B, the difference is an int type length, 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, precise Layout
You need to use fieldoffset () to set the location of each member.
In this way, the function of a public body similar to C can be implemented.
[Structlayout (layoutkind. explicit)]
Struct S1
{
[Fieldoffset (0)]
Int;
[Fieldoffset (0)]
Int B;
}
In this way, A and B are in the same memory address.

 

Okay, it's easy to understand.

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.