Data Structure of linux kernel source code learning, linux source code

Source: Internet
Author: User

Data Structure of linux kernel source code learning, linux source code

This article records some data structures that you know but are not familiar with when learning the Linux kernel source code.

Union

It is encountered in the learning process replication function do_fork:

<Sched. h>
Union thread_union {
Struct thread_info;
Unsigned long stack [THREAD_SIZE/sizeof (long)];
};

Struct thread_info and stack are declared as union Shared Space

"Union" is a special class and a data structure of the construction type. Different data types can be defined in a "union". In a variable described as the "union" type, any type of data defined by the Union can be loaded. The data is shared with the same memory segment, which has saved space (there is also a space-saving type: Bit domain ). This is a very special feature and also a feature of union. In addition, like struct, Union default access permissions are also public and also have member functions.

The allocated space of a union instance is similar to struct, which is divided by an integer multiple of the maximum number of bytes occupied by its internal data type. The space occupied by each union instance in e.g. Is 3*4 = 12.

Union foo
{
Char s [10];
Int I;
};

Since union data members share a single memory space, you must access the correct members to correctly read the variable value, you can use an additional variable or list type to record which member used the space for the last time.

Reference: http://baike.baidu.com/view/109447.htm? Fr = aladdin

There are the following differences between a shared object and a struct:
1. the shared body and struct are composed of multiple members of different data types. However, at any time, the shared body only contains one selected member, and all the members of the struct exist.
2. assigning values to different members of the shared body will overwrite the values of other Members. The original values of the members do not exist, but the assignment values of different members of the struct do not affect each other.


Linux kernel source code scenario analysis is suitable for beginners of linux

If you have basic C language and have a better understanding of the linux file system, you can directly look at the linux kernel source code analysis.
 
What is the basis for learning the Linux kernel source code?

C language + operating system knowledge (required)

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.