Exploration path

zhaozj2021-02-16  46

Exploration Road Zero

When college computer theory knowledge, there is often a kind of inexplicable failure, not because the exam is not bad; it is troubled by an unprecedented confusion. For example, I don't know how the computer will perform the code I wrote, and I don't know what the computer is holding what kind of mind to see my clumsy code; I don't know how the code I wrote is how to go. I have been dealing with the interface; I don't know why I can go online; I don't even know what software is developing; I only know, I write some logic code, then compile, then compile, then compile, then compile, Then my computer runs inexplicably, then I don't know anything.惘, angry, angry, there is no, only to take courage, start to explore the way, the party is the way. Although the computer appears to be mysterious and incredible, after the effort is explored, it can still find the eyebrows; the author has written some experiences, hoping to help the teachers who have just involved in the computer, and also hope that the masters will criticize their guidance.

First, how the computer is executed

Everyone knows that the program code is essentially a series of instructions, and some pre-designed command sequences. For example, the user wants to know the result of the two numbers; then as a programmer, we may need to design an interface in advance under Windows, and we may also need to provide an execution. Buttons, after the user presses the button, output the result to the user. From the display interface to the output result, these behaviors are all we use the code to command the computer, this is a small program design. If you describe the two numbers added to the C language probably such a "z = x y;", it is a pity that the computer is too stupid. I don't know what "z = x y;" means, the computer can identify Only machine language, what is the machine language? It can be understood: We know that in the digital circuit, we can control the current level. If we use the high low of the current, and use the symbol of the binary form to represent a high and low current string, such as 1 means high 0 represented low, This can form binary data; now we can represent different behaviors of the computer according to the difference in binary data (actually different changes in the current), such as "111111" to represent two numbers, "111110 "Indicates two numbers, so that the manufacturer of the computer can use binary data (actually a change in current) to specify a series of behavior (commands); the same, for the data we have to handle Binary data is represented, this is a machine language; further, we use the easy-to-understand string to binary commands and binary data, so that it is easy to understand the string of the binary form, one by one, This forms a assembly language; for example, using add represents "111111" two numbers. Now I use the C language that belongs to a higher level, and he makes us ordered the computer to do things more easily; he does not correspond to the same one by one by the machine language; but use the compilation software to describe the shape of the C language To transform into a machine language (semantic equal), so that the computer can identify. That is, whether C / C is also a Pascal language, for the same machine, the final generated is the same machine (or assembly) language, but the grammar is different. In this way, the high-level language has a benefit that the machine is independent, which allows us to write the program to correctly run the computer produced by different manufacturers without having to rewrite a set of procedures for each machine; of course, The premise is that computer generators should write compilation programs for this advanced language to generate corresponding machine languages. As mentioned above, C language needs to form a machine language (or assembly language) according to semantic compilation, so that how does C syntax represents semantics? Here, I briefly introduced an example, I am interested in understanding the common friend's friends, I can see the "depth exploration C object model".

For example, I set the following categories: class test {private: long a; long b; public: long getavalue (); long getbvalue ();}; long test :: getavalue () {Return A;}; longue () {RETURN B;}; there is the following code: Test * Ptest; ptest = new test; lgtemp = ptest-> getavalue (); then Test * PTest, semantics, define a Test type pointer, if this pointer points to Data, then it can be legally accessed to access the two-row of eight bytes it point to (the LONG type accounts for four byte memory, and there are two LONG type members in the Test class, so eight bytes). PTEST = New Test, the system dynamically assigns eight bytes of memory, and causes the Test class pointer PTest points to this newly assigned memory segment (Note: There is no memory for the member function). LGTEMP = PTEST-> The semantics of getavalue () are: calling TEST's member function getAvalue () and saves the results in LGTEMP. This function returns the result to lgtemp may have two internal implementations (the compiler will make some hands and feet of our code to facilitate the conversion to machine language); First,: PTEST-> GetAvalue (lgtemp, this) {lgtemp = this- > a;} second is: long LGADD_TEMP; PTEST-> getavalue (lgadd_temp, this) {lgadd_temp = this-> a;} lgtemp = lgadd_temp; there is still a problem, New Test does not generate the GetAvalue function address, we How do I find GetAvalue and call him? The answer is that the compiler generates a table related to the scope. We already know that PTEST is a Test class object before calling getAvalue. The compiler will find the location of the Test class in the scope table and find the address of the getAvalue function. (Function Name corresponds to the function address). For details, you can see the principle of compilation, and the author will not be quite clear. Summarize, the process of computer execution of the code we wrote is probably like this: compile the code we wrote into an executable file; execute the executable, the operating system creates a new process, and allocates resources for this process, such as memory space Reduce the code in the executable file into the code segment in the process memory space; find the entry point of the program, call the main function to start executing the program; when the dynamic link library needs to be called during the execution, the dynamic is allocated in the process space. And transfer it to, dynamic libraries manage new allocated memory releases; allocate memory on the stack for local variables or global variables in the program, but do not need to write code to manage this part of the memory; we write code on the pile Dynamically assigned memory, you need to write code to control the release of this part of memory, otherwise memory leaks; complete our task, release the resource allocated by the process, exit the program. Second, the troubles of data management

The work that the CPU can do is actually very simple. The procedures we have written will eventually become a robot directive to the team's team; the CPU only reads a directive, and find this instruction in the content of the data segment in the instruction. The data to be processed is then processed by the requirements of the instruction. Among them, the data to be processed can come to yourself memory, hard disk, register, etc., and the data after the instruction processed can also be placed in memory, hard disk, register, etc., the one can do very limited, in order to make the machine can be We do what is also amendy, we must go to control relationships with the management instructions and instructions (for example, we make the execution result of a directive as the processing object of the next directive), so that we work together to implement the functions we want. Usually, when we want to computers, you will perform an application, an application represents a collection of commands and collection of data to be processed; in order to facilitate access to the instructions, we Create a process and assign a very large logical process address space for this process, the CPU can easily access the data within this address range, because the memory does not have such a huge, so actually allocates the physical address of the memory. The space is just a small part of the process address space; "Collection of a series of commands and the collection of data to be processed" is imported into the address memory space that assigns memory, and this address space is preferably continuous and Order, to facilitate the CPU access data and instructions. The CPU directive is also good, but the data of the CPU operation is often dynamically allocated and is often changed, so many troubles will often be encountered. For example, a string STRA is stored in the memory address space 1000--1030, and another string strb is stored at address 1032--1050; the CPU finds this string strand in the execution of the program according to the address 1000. We may have to increase STRA content, such as adding 10 characters, but there is a string in address 1032, if these new characters are added to 1030, it will also cover the data of StrB, this is what we don't want to see The two solutions are available, one is to reassign a sufficiently large memory to Stra and point the pointer of the operation STRA to this newly assigned address, the original 1000--1030 is released for later use, two It is more assigned to STRA allocation to STRA, so that it can be added later when it is to grow, but this is a waste of memory. During the execution of the program, a large number of behaviors of this data change, how to manage data in memory is very headache. It may be because of this problem, the artificial coded address space in the process address space will not change the length of the code segment address space, and the frequently changed stack segment address space, etc. to facilitate management data. For programmers, the most concerned is the changes in the stack segment data, and exhausted to manage him to ensure that the program is highly efficient. Similar problems have been encountered for data in the management disk. For example, I have three text files A, B and C, the size is 10m, b in the middle of A and C space, and assume that three files are continuously placed in a 30m disk space.

We often have operations on the file, modify a certain segment data in the file (file therefore possible to grow shorter), add data to the file head or file, etc., and our operation of the disk data is through the disk pointer The read and write data is completed, the disk read and write data needs to move the pointer, the movement of the disk pointer (especially the movement between the tracks) is relatively slow, so the best way to improve the speed of reading and writing data is to put To read the data in a continuous data disk space, or write the data you want to write in a continuous address space to avoid frequent disk pointers. So, when I modify the file B, I may encounter three situations, one is that the file is small, and the other is that the file is large, the third is the size. For files, when we just delete (modify) file tail, we will not encounter what trouble, but when we modify a small paragraph in the file, even just delete a character, we will encounter a lot Trouble: Because there are less data in the middle of the file, in order to ensure the continuity of the data, we can move the data after the modification, but if the modification is near the file, we will need to move nearly 10m data. (Think about it, I just delete a character, you have to move 10M data, too unfair!), Of course, we don't have to make data continuous. For files, it is more troublesome, because there is a after the B file, there is C, there is no extra space to make him bigger, so it is only possible to allocate a large enough continuous space in the disk ( Even if the file only increases the size of a character), the boutique space is also reclaimed because it is not used. There is also a small problem, when the space of the B file is recovered, when reuse this space, if the size of another file is 11m, then this space does not save; if it is 5m, it may cause waste 5M. Of course, the remaining 5M can also be used to store files less than 5m. Ok, the problem that is encountered when managing disk data has been listed. Now let's play our extraordinary imagination. Think about what we usually make for the documents, and then think about to meet our desire to do Work, is it horrible? For problems you have encountered above, there is a compromised solution that cuts the file into a small data block, where the data within each data block is continuous, then use a chain to chain it. When we modify the data in the file, you can usually need to modify a data block to meet the needs, and do not need to modify the entire file, then re-connect the modified data block to the list of data files. . In the operating system file management, such a data block, I heard that it is 1K size, too big and too small. In modern database technology, there are also data block concepts. Different, databases are more, in addition to useful data, in addition to useful data, to facilitate the growth of data within the data block; There are two items PCT_USER in Oracle, and PCT_FREE is used to control this free space. Of course, for efficiency and simple, not all operating systems are willing to divide files, the author knows that there is a network operating system called Mach, and the data in the file is definitely continuously stored. The price is not allowed to modify the file. If you don't want to modify, you can only create a way of deleting the original file and create a way of the same name file. The problems encountered when computer management data are far more than these.

Here, I will give an example: When we have to deal with the amount of data very large, the data will become confusing, how do we make these data? How do we find the data we want? At this time, the file management system of the operating system can no longer meet the needs, we need a new technology, database management technology. Database management technology is more flexibly divided into the data we have to process more flexibly than the file management system and more reflects the relationship between the data to be processed; if the data to be processed into a database, Several levels of data sheets, records, etc. are managed, and there is a certain relationship between the tables and the tables in the database, and there is a certain relationship between the records and records in the table. Of course, to make the database should have a role in this great technology, we need to use our users to use it. For problems encountered when database management data, here is not detailed, interested friends recommend to see "Database Principle, Programming and Performance", mechanical publishing, in place for performance. Third, the exchange of procedures and users

A household computer, composed of CPU, memory, motherboard, hard disk, mouse, keyboard, display, optical drive, floppy drive, etc. We communicate commands to the computer through the keyboard, and the computer is displayed by the display to show us; one seems to be so natural, just I don't know if you have thought about it, how do you think of us? These behaviors? How is the mouse, keyboard, and monitor play their role? In fact, in the computer, our operation is in him (correctly the programmer writing the program programmer); and when we have made something expensive, he can't be correct. Run, either report a wrong, or simply dead. And the mouse, keyboard, display of these devices is just our communication tools with computers. Now let's take a look at the mouse, keyboard, monitor, can provide us with some of the services, what kind of responsibility has their own responsibilities and how to communicate with computers. Mouse, the mouse can help the computer locate a location in the display, and use this position as hotspot, through the moving CPU, you can accurately locate each pixel point of the display; if we build a right-angle coordinate system, the mouse The function is manifested as a computer with a coordinate value (x, y); the mouse movement (x, y) value is correspondingly followed, to indicate that the hotspot is moved on the screen. The mouse can also provide a computer with left and right click, double-click, etc. If the coordinate value of the hotspot on the screen can make the computer know what we do at the position of the screen; This is the responsibility of the mouse and what he can do. The keyboard can provide more than 100 different signals for your computer and specify the meaning of these signals, through different combinations of these signals, communicate with computer. Display, no, just display some beautiful interface to see us, graphically, imagely. We use the mouse to operate with the keyboard to make it easy for us to control the computer. In the interaction of the computer and the display, we can use the API function to draw on the screen, write; whether it is a picture or writing, the purpose is just to make it easy for users to communicate with the computer, as for these words, these words from there, how come It is not interested in the display. We also know that Windows is a "event-based, message-driven" operating system; also, we can only run the system by sending messages to the operating system. What is an event, what is the news? We perform a program in Windows, usually see one of the windows in the display, as long as we use the mouse or keyboard, there is actions to the window (such as changing the window size or move, click the mouse or press the keyboard one button, etc. This action is an "event". When an event is detected each time, a "message" will be sent to the program, so that the program performs the corresponding code to process the event. So our programming work has become, to process this message or this event for every event, each message, and the code, and the code of these response messages is destined, and it has formed an application. .

There is still a small problem, just mentioned that the size of the change window will generate a message, and the display is only responsible for displaying, other inventions, how is the message generated, when is it generated? When we use the left mouse button to maximize the maximum button in the upper right corner of the window, the window will become bigger, the message is generated at this time, just in the moment we press the mouse! Under Windows, in order to facilitate our writing programs, there will be some packaging processing on the keyboard and mouse. For example, we also change the window size as a message, here we assume a function funsize to package Handling this event; in this way, when the mouse left hits the maximum button message, the function funsize can be called to process (see a message to activate another message), and the window is brought to the mouse and drag the window. When the message can also be called, Funsize can be called to handle, and the benefits of doing this are obvious. Ok, now summarize, mouse, monitor, CPU change this matter on the window size, how to divide us: When the mouse moves to the maximum button of a window and left hits, the mouse tells the CPU two information, currently The position of the mouse (x, y), the current mouse action (left click); because the new message is generated, the CPU interrupts the current work; then view the screen in memory according to the mouse (x, y) in memory. The part of the data, see (x, y) this location is currently the top window, then send a message to this window; by viewing memory data, at this time, the CPU also knows that the mouse is currently moving to the maximum button of the window. On, and press the left button, so I know what he has to do, maximize the window; after knowing the task, the CPU will work immediately, re-adjust the window data, so that it satisfies the need for the window to maximize the display; then call the API draw function Heavy paintings the entire window; then we can see the maximized window on the screen. Fourth, communication

When I was in Guangzhou, I found that there was no money in the pocket. I would call home and reached out to my father; of course, I can also choose to write home, calling my father to send some money; then Dad will put money There is a bank account, then I can go to the bank to use it. I don't know if you have thought about it, from no money, call Dad money money, from banking, this series of behaviors can be successfully carried out? In order to call Dad, I must know the phone number in advance, or the family address, so I have a way to contact my father; second, I have to understand Cantonese, I know Cantonese, my father can understand Cantonese, so I After opening the phone, you can communicate normally; or, if you write, I have to write Chinese characters, my father knows Chinese characters. This is the communication situation in our lives, then what is the communication between the computer? In fact, communication between computers is very similar to what I communicate with my father. If you change money to the computer, you may be like this. I am a client, my father is a server, the phone number and address of the home are the server's IP address and port number; the bank's account is the client's IP address and port number; calling is to choose TCP / IP communication protocol communication, write a letter That is to choose UDP / IP communication protocol communication; Chinese characters and Cantonese is the communication protocol defined by the server and the client, and the money is the output data after the server. My father is not always staying at home. He has to work hard, but you can't go home. If he doesn't go home, no one can listen, write a letter No one is receiving, then I can't ask him. I am paying money, so he must have to go home in a session; Similarly, the server has to listen to the port. Every time I see if there is no new task. Send money, I usually choose to call this kind of communication method, because it is convenient and fast; but if you want to talk to Dad, you will describe the school life, call us often, if you write, I have sufficient Time to organize the language; it can be seen that there are two ways to call and write. Similarly, the TCP / IP protocol is established is a reliable connection-oriented communication protocol. He guarantees the reliability and correct data transmission, but if the server is to maintain N connectivity, when N is very At the big time, this cost will be very high; the UDP / IP Communication Agreement is relatively light for N customers at the same time (no need to maintain N connectivity at the same time), but the reliability and correctness of the data; therefore, Director. It can be seen that the communication in real life is similar to the communication between computers! There is almost a corresponding shadow in the realistic in the computer communication; if our head can turn around, maybe it can solve the problem in the realistic way to solve the problem of communication between the computer. Through the above description, careful friends, there is probably a problem that has been perceived; the communication of real life is communicating, because - knowledge! Communication knowledge is knowledgeable! Think about it, when we are born, you will not speak, you will not know if you have a gesture, you don't understand your stomach. At this time, you can only cry, so that your mother thinks enough time. Feeding.

Later, we learned to speak, and also learned to walk, fight, stomach, and also learned to steal the east and eaten, and he was caught by his mother and said to be a defense. Now, we will implement Mandarin in the country. If you only understand Cantonese, you can't talk to the local people in Beijing, Tibet, and you will have a good thing. Fortunately, I also learned Mandarin, you can easily communicate with the local compatriots, ask, buy There is not a problem. But I am very impressive. If you go to the United States, you can probably guessed that I will happen. So, in order to communicate normally in the world, popular English in the world (the day! Why is it not Mandarin!) It is so important. Knowledge is the basis of our human social communications; then what is the basis of communication when the computer world? Agreement, communication protocol! Starting from the level of level, it creates a set of protocols for different applications of different applications world-recognized, forming a machine language, forming data; then assembly, c, c , sql, etc., is this set of sets The appearance of the agreement, a set of standard formulations, the structure appears in colorful modern computer world. Conclusion

"The road is long and the road is long, I will go up and down", I have chosen the road of walking, I have to make full psychology, accept the challenge of endowed the technology, and bear the responsibility of innovation; friends go to the road together, More than one friend, less lonely, more than one harvest.

2003.6.13

转载请注明原文地址:https://www.9cbs.com/read-25689.html

New Post(0)