当前位置:网站首页>Data storage in memory & loading into memory to make the program run

Data storage in memory & loading into memory to make the program run

2022-07-06 16:04:00 Programming fish 66

The information that a computer has to process is diverse , Like numbers 、 written words 、 Symbol 、 graphics 、 Audio 、 Video etc. , This information is different in people's eyes . But for computers , They are all the same in memory , All in binary form .

To learn programming , You have to understand binary , It is the basis of computer processing data .

Memory module is a very precise component , It contains hundreds of millions of electronic components , They are very small , At the nanometer level . These components , It's actually a circuit ; The voltage of the circuit will change , Or 0V, Or 5V, There are only two voltages .5V It's power on , use 1 To express ,0V It's a power outage , use 0 To express . therefore , One component has 2 States ,0 perhaps 1.

We use the circuit to control the power on and off of these components , There will be a lot of 0、1 The combination of . for example ,8 There are 28=256 Different combinations ,16 There are 216=65536 Different combinations . Although a component can only represent 2 A numerical , But a lot of values can be represented by a combination of many .

We can give each combination a specific meaning , for example , It can be used separately 1101000、00011100、11111111

To express C、 language 、 said , This a few word , So combine 1101000 00011100 11111111 It means ”C Language “

In general, we don't use components one by one , It's going to be 8 A component is a unit , Even if it means a very small number , for example 1, Also needed 8 individual , That is to say 00000001.

1 The components are called 1 The bit (Bit) or 1 position ,8 The components are called 1 byte (Byte), that 16 A component is 2Byte,32 One is 4Byte, And so on :

8×1024 A component is 1024Byte, Shorthand for 1KB;

8×1024×1024 A component is 1024KB, Shorthand for 1MB;

8×1024×1024×1024 A component is 1024MB, Shorthand for 1GB.

Now? , You know, 1GB How many components do you have in your memory . What we usually call the file size KB、 How many? MB, That's what it means .
Unit conversion :

  • 1Byte = 8 Bit
  • 1KB = 1024Byte = 210Byte
  • 1MB = 1024KB = 220Byte
  • 1GB = 1024MB = 230Byte
  • 1TB = 1024GB = 240Byte
  • 1PB = 1024TB = 250Byte
  • 1EB = 1024PB = 260Byte

When we usually use computers , Usually it's only designed to KB、MB、GB、TB These units ,PB and EB These two advanced units are generally used in the process of big data processing .

You see , There is no... In memory abc Such characters , either gif、jpg Such a picture , Only 0 and 1 Two figures , Computers only know 0 and 1. therefore , Computers use binary , Not the familiar decimal system , Data written to memory , Will be converted to 0 and 1 The combination of .

Programmer's humor

To impress , Finally, let's see a joke .

The programmer A:“ cronies , I'm short of money recently , Borrow some money ?”

The programmer B:“ Yes , How many do you want? ?”

The programmer A:“ A thousand lines No ?”

The programmer B:“ Who are we with ! I'll round it up for you ,1024, Take it .”

Do you understand the joke ? Please choose the right answer .

A) Because he sympathizes with programmers A, Give him more 24 block
B) This programmer can't count , Maybe it's too poor and hungry
C) This programmer intentionally , Because his dictatorial wife rules 1024 Is an integer
D) It's like 100 yes 10 To the power of an integer ,1024 yes 2 Integer power of , For programmers, it's integers

Study with the webmaster , Every day there is progress .

Easy to understand , Explain profound theories in simple language , An article only talks about one point of knowledge .

The article is not abstruse , There's no need to delve into , On the bus 、 On the subway 、 You can read in the toilet , Go up anytime, anywhere .

The article does not cover code , Do not burn brain cells , Everyone can learn .

When you decide to join C Language /C++ Programming learning base :828339809, You have surpassed 90% The programmer !


Load memory , Let the program run

If you have installed QQ, You want to chat with your friends , Double click QQ Icon , open QQ Software , Enter account number and password , Then log in .

that ,QQ How did it work ?

First , One thing you need to be clear about , You installed QQ The software is stored on the hard disk .

double-click QQ Icon , The operating system will know that you want to run this software , It will find your installation in the hard disk QQ Software , Put the data ( The software installed is essentially a collection of a lot of data ) Copy to memory . Yes ! Copy to memory !QQ Not running on a hard disk , It's running in memory .

Why? ? Because the reading and writing speed of memory is much faster than that of hard disk .
For read and write speed , Memory > Solid state disk > Mechanical drive . Mechanical hard disk drives the disk to rotate by motor to read and write data , The memory module reads and writes data through circuits , The speed of the motor must not have the transmission speed of electricity ( Almost the speed of light ) fast . Although solid state drives also read and write data through circuits , But because it is different from the control mode of memory , It's not as fast as memory .

therefore , Whether it's running QQ Or editor Word file , First copy the data on the hard disk to the memory , To make CPU To deal with it , This process is called loading memory (Load into Memory). This process requires a special program ( Software ), This program is called loader (Loader).

CPU Dealing directly with memory , It reads the data in memory for processing , And save the results to memory . If you need to save to hard disk , Will copy the data in memory to the hard disk .

for example , open Word file , Enter some text , Although what we see is different , But the document in the hard disk has not changed , The newly added text is temporarily saved to memory ,Ctrl+S Will be saved to the hard disk . Because data will be lost after memory power failure , So if you finish editing Word If you forget to save the document, you shut down , So you'll never get it back .

Virtual memory

If we run more programs , It takes up more space than memory ( Memory module ) Capacity . For example, the memory capacity of a computer is 2G, But it's running 10 Procedures , this 10 Programs occupy a total of 3G Space , That means you need to copy from your hard drive 3G Data to memory , It's obviously impossible .

operating system (Operating System, abbreviation OS) Solved this problem for us : When the space required for program operation is greater than the memory capacity , The temporarily unused data in memory will be written back to the hard disk ; Read the data from the hard disk when you need it , And write another part of the unused data to the hard disk . such , There will be some space in the hard disk to store temporarily unused data in memory . This part of space is called virtual memory (Virtual Memory).

3G - 2G = 1G, The above situation needs to be allocated on the hard disk 1G Virtual memory .
The reading and writing speed of hard disk is much slower than that of memory , It takes a lot of time to exchange data repeatedly , So if your memory is too small , It will seriously affect the running speed of the computer , It will even appear ” stuck “ The phenomenon , Even if CPU powerful , It won't make a big difference . If economic conditions permit , It is recommended to upgrade the memory to 4G, stay win7、win8、win10 The software will run smoothly under .

More about memory , Everyone is learning 《C Language introduction tutorial 》 after , Please read on 《C Language and memory 》, I'm sure you'll have an epiphany .

summary :CPU Read data directly from memory , After processing, write the result to memory .

chart 1:CPU、 Memory 、 The relationship between hard disk and motherboard

 

Study with the webmaster , Every day there is progress .

Easy to understand , Explain profound theories in simple language , An article only talks about one point of knowledge .

The article is not abstruse , There's no need to delve into , On the bus 、 On the subway 、 You can read in the toilet , Go up anytime, anywhere .

The article does not cover code , Do not burn brain cells , Everyone can learn .

When you decide to join C Language /C++ Programming learning base :828339809, You have surpassed 90% The programmer !

原网站

版权声明
本文为[Programming fish 66]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060919348692.html