当前位置:网站首页>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 !
边栏推荐
- Hdu-6025-prime sequence (girls' competition)
- Penetration test (3) -- Metasploit framework (MSF)
- [exercise-6] (PTA) divide and conquer
- 【练习-10】 Unread Messages(未读消息)
- Truck History
- 树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控
- 【练习-6】(PTA)分而治之
- [exercise 4-1] cake distribution
- Interval sum ----- discretization
- China potato slicer market trend report, technical dynamic innovation and market forecast
猜你喜欢
Record of force deduction and question brushing
Optimization method of path problem before dynamic planning
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
STM32 learning record: LED light flashes (register version)
Penetration test 2 --- XSS, CSRF, file upload, file inclusion, deserialization vulnerability
Gartner: five suggestions on best practices for zero trust network access
X-Forwarded-For详解、如何获取到客户端IP
Information security - Analysis of security orchestration automation and response (soar) technology
1010 things that college students majoring in it must do before graduation
Determine the Photo Position
随机推荐
差分(一维,二维,三维) 蓝桥杯三体攻击
最全编程语言在线 API 文档
Opencv learning log 12 binarization of Otsu method
E. Breaking the Wall
Record of brushing questions with force deduction -- complete knapsack problem (I)
信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
Analysis of protobuf format of real-time barrage and historical barrage at station B
VS2019初步使用
0 - 1 problème de sac à dos (1)
7-1 understand everything (20 points)
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
Penetration test (4) -- detailed explanation of meterpreter command
滲透測試 ( 1 ) --- 必備 工具、導航
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
SSM框架常用配置文件
frida hook so层、protobuf 数据解析
X-Forwarded-For详解、如何获取到客户端IP
Frida hook so layer, protobuf data analysis
区间和------离散化
Ball Dropping