Operating procedures principles

  Introduced a website, http://c.biancheng.net/cpp/html/3450.html good introduction to the C, C suitable for learning and get to the bottom with. . . (C programming network, is now also the charges!)

  Some free learning resources: https://cloud.tencent.com/developer/article/1184830

1, a program in the computer in the end is how it works?

  Program is stored in the hard disk to be loaded into memory to run, CPU is also designed to be read only data and instructions from memory;

  For the CPU, the memory is merely a place to store instructions and data, and can not complete the calculation in the memory function, to understand the specific operation process, look at the structure of the CPU:

  CPU computer component is a complex, which contains a lot of small parts and interior, as shown below:

  

 

  Brain arithmetic unit CPU is responsible for addition, subtraction, comparison, displacement computing tasks, each operation has a corresponding support circuitry, very fast.

  Internal CPU registers are very small, very fast storage means, its capacity is limited, to the CPU 32, each capable of storing 32-bit general registers (4 bytes) of data for the CPU 64, each general register capable of storing 64-bit (8-byte) data. In order to complete a variety of complex functions, the modern CPU have built dozens or even hundreds of registers, embedded system features a single, small number of registers;

  We often say how many CPU, refers to the number of bits of the register; register is crucial in the process of execution of the program, indispensable, they can be used to perform mathematical calculations, control cycles, control the execution flow of the program, flag operating status of the CPU.

  Why have to set the internal CPU cache it?

  Although the memory read speed has been very fast, but the CPU and compared, there are still a big gap, not an order of magnitude, if every time data is read from memory, will seriously slow down the speed of the CPU, CPU often in a wait state, nothing to do. Setting a cache inside the CPU, you can use frequent data being read into the cache, the data is needed on the same address, they do not go all the way to access memory, can be read directly from the cache.

  We will often concerned about when buying CPU cache capacity, for example: Intel Core i7 3770K three-level cache is 8MB, the secondary cache is 256KB, a cache is 32KB, the greater the capacity, the more powerful CPU.

  The buffer capacity is limited, the CPU can only read from the cache to the data portion, using the data is not very frequent, would bypass the cache, read directly into memory. So do not always get the data from the cache, which is a cache hit rate, it can be read from the cache hit, otherwise it would have died in. About the cache hit rate is a science, what data remains in the buffer, which data is not retained, there are complex algorithms.

  To get CPU work, must use special instructions, such as add a summation, for Sub division, the number of CMP for comparing the size of two, which is called the CPU instruction set (Instruction Set). Our C language code will eventually be compiled into a one of the CPU instruction. CPU support of different types of assembly instructions vary, but most are the same.

  In fact, the above code is in assembly language, not the CPU instructions, assembly language to go through in order to become a simple conversion CPU instructions; In order to more easily illustrate the problem, these statements do not strictly abide by the assembler syntax. Interested students can self-learn assembly language, not to undertake to explain here.

2, loaded into memory, let the program up and running

  If the QQ installed on your computer, and you want to chat with friends, QQ can double-click the icon to open the QQ software, enter the account number and password, and then log on it. So, QQ is how to run up it?
  First of all, one thing you must be clear, QQ software you install is stored in the hard disk. Double-click the icon QQ, the operating system will know that you want to run this software, it will find QQ software you install on your hard drive, copy the data (to install the software essentially is a collection of a lot of data) into memory. Correct! It is copied to memory! QQ is not running on the hard drive, but running in memory. why? Because the memory read and write speeds much faster than hard drives. For read and write speed, memory> SSD> mechanical hard drive. Mechanical hard disk drive is rotated by the motor to read and write data, and to read and write data memory circuit, the motor speed is certainly not the transmission rate electricity (speed of light almost) fast. Although solid state drive is reading and writing data through the circuit, but not the same as the control and memory, and memory speed is not. So, whether it is running QQ or edit Word documents are copied data on the hard disk into memory first, in order to allow the CPU to handle, this process is called load memory (Load into Memory). Complete this process requires a special program (software), this program is called Loader (Loader). CPU deal directly with the memory, it will read the data in memory processes, results are saved to memory. If you need to save to your hard disk before copying the data in memory to the hard disk. For example, open a Word document, type some text, although we see not the same, but the document does not change the hard drive, the new text temporarily saved to memory, Ctrl + S will save to your hard drive. Because it will lose data after power failure memory, so if you finish editing a Word document forget to save it off, and then you will never be able to retrieve the contents.

Virtual Memory

  If the program we run more, will exceed the space occupied by memory (memory) capacity. For example computer's memory capacity is 2G, but running 10 programs, 10 programs which occupy a total of 3G space, which means 3G need to copy data from the hard disk into memory, which is obviously impossible. OS (Operating System, referred to as OS) for us to solve this problem: When the space needed for the operation of the program is greater than the memory capacity, the memory will temporarily not write data back to the hard disk; and then read from the hard disk when data is needed and another part not written to disk data. In this way, there will be a portion of the hard disk memory space used to store data temporarily unused. This part of the space is called virtual memory (Virtual Memory). 3G - 2G = 1G, 1G above situation needs to allocate virtual memory on the hard disk. Hard disk read and write speeds much slower than memory, repeatedly exchange data consumes a lot of time, so if your memory is too small, it will seriously affect the computer speed, even a "stuck" phenomenon, even if the CPU is strong, it will not a big difference. If economic conditions permit, it is recommended memory upgrade to 4G, in win7, win8, the software will run under win10 relatively fluent.

 Reference: "C language and memory" (fee)

 

Guess you like

Origin www.cnblogs.com/WPF-342201/p/11420590.html