当前位置:网站首页>Standard C language 6
Standard C language 6
2022-07-25 06:27:00 【Luo CS】
nineteen 、 Process image
Program : Executable files stored on disk ( Binary 、 Script files )
process : Procedures in progress in the system , Load data into memory and run
Process image : It refers to the distribution of process memory
text Code segment Store binary instructions 、 const data By const Decorated initialized global variables and static local variables
Permissions are read-only
data Data segment Initialized global variables ; Initializing static local variables
bss Static data segment Uninitialized global variables , The memory of a given segment will be automatically cleaned up as 0;
Uninitialized static local variables , Default cleanup is 0;
stack Stack local variable 、 Block variable ( Operating system management , It will automatically apply for 、 Free memory , Small memory )
heap Pile up It is managed manually by programmers ( Large memory ,)
Global and local variables
local variable : Variables defined in functions
Storage location :stack Stack memory
Life cycle : From the beginning of the function call to the end of the function
Scope of action : Can only be used within a function
Global variables : Variables defined outside the function
Storage location :data( initialization )、bss( uninitialized )
Life cycle : From the beginning of the program to the end of the program
Scope of action : It can be used anywhere in the program
Block variable : Variables defined in a statement block (if/for/while)
Storage location :stack Stack memory
Life cycle : From the beginning of the function call to the end of the function
Scope of action : Can only be used within a statement block
Be careful : When a local variable has the same name as a global variable , Local variables in functions mask global variables ;
Block variables mask global and local variables ( Global variables are capitalized ,)
twenty 、 Type qualifier
(auto) Define automatic memory allocation 、 Free variables in memory ( local variable )
Global variables cannot be used auto,C11 The standard is used to automatically identify types ;
extern Declare variables ( Global variables )(extern Type name Variable name ),
Tell the compiler that this variable has been defined elsewhere . Let the compilation pass temporarily , Link not found , Will report a mistake
Cannot assign values when declaring variables
In multi file programming , hypothesis a.c Global variables are defined ,b.c To use , Need .
static Static variables ()
Change storage location ;
Change the storage location of local variables stack -> data / bss( Initialize to 0, Store in bss)
static Modified local variables It's called Static local variables
Extending the life cycle ;
Prolongs the life cycle of local variables : The end of the function will not be destroyed , Until the end of the process
Limit the scope of action ;
Limit global variables 、 The scope of the function , Use only in this document .
Can prevent global variables 、 Function name naming conflict ; Prevent other documents from using
const “ Protect ” The value of a variable cannot be changed explicitly , But you can modify the value by accessing memory
But if you decorate the initialized global variables 、 Initialized static local variables ,
Then the variable will change from data Change it to text, Turned into “ Constant ” Cannot force modification
volatile If the value of the variable is not displayed and modified , Then when using this variable, it will not be read from memory
Instead, continue to use the last read result , This process is called value optimization , It's usually done ;
Variable is volatile After retouching , The compiler does not optimize the value of this variable , Every time
Reread from memory .
General hardware programming 、 Multi line programming will use ;
register register , Apply to change the storage medium of variables from memory to registers , Because of the limited number of registers
Not necessarily successful .
Be careful : Register variables cannot take addresses
storage medium : Hard disk -> Memory -> Advanced caching -> register
typedef Type redefinition ,
When defining variables , If you add typedef, The variable name becomes the new type name of this type
Be careful :typedef Not a replacement type
The 21st 、 Function recursion
This behavior of function calling itself is called function recursion , Improper use will lead to dead circulation
Recursion is an algorithm that can realize divide and conquer , Put a complex big problem , Break it down into several small problems , Until all the problems are solved
How to write recursion well :
1. Find the exit
2. Solve a small problem
3. Call yourself
Each call of the recursive function will produce its own copy in the stack memory , Until the implementation to the export
Will release this layer of recursive functions , therefore , Compared with the cycle , Recursion is very memory intensive , slowly ,
If you can use functions, don't use recursion
advantage :
1. A good understanding 、 have a lucid brain
2. Good solution to nonlinear problems
shortcoming :
1. Memory consumption , slowly
边栏推荐
- Netease game Flink SQL platform practice
- MySQL index collation summary
- It is said that screentogif is a GIF recording artifact, but I don't know that its strength is far from here
- 函数模板学习记录
- The code spell checker plug-in avoids some specific vocabulary errors "XXX": unknown word.cspell
- JZ7 重建二叉树
- Detailed explanation of the difference, working principle and basic structure between NMOS and PMOS
- MySQL queries the table name under the current database
- Android interview question: why do activities rebuild ViewModel and still exist—— Jetpack series (3)
- 【datawhale202207】强化学习:强化学习基础
猜你喜欢

都说ScreenToGif是GIF录制神器,却不知其强大之处远不在此

Use abp Zero builds a third-party login module (III): web side development

Unity model simplification / consolidation one click plug-in

Mlx90640 infrared thermal imager temperature measurement module development notes (I)

How to play a data mining game entry Edition

C control open source library: download of metroframework

Data too long for column ‘data‘ at row 1以及设置成longblob造成的乱码解决。node-mysql

JTAG debugging source level debugging of arm bare board debugging

Evolution of coupon architecture under C2B mode
![[QT] solve the problem of Chinese garbled code output from QT console](/img/09/8af91d2a0327bd1d3c7b64f2b8185f.png)
[QT] solve the problem of Chinese garbled code output from QT console
随机推荐
Scientific computing library numpy Foundation & Improvement (Understanding + explanation of important functions)
Common API of window
Koa2 learning
JZ7 重建二叉树
MFC IniFile Unicode mode reading method
Bug notes
When the graduation season comes, are you ready? What are we going to do
【Node】服务端口被占用Error: listen EADDRINUSE: address already in use :::9000-如何关闭node启动的端口
VSCode 如何开启多个终端?如何横向显示?
Download and run the C open source control metroframework demo project
GF Securities online account opening? Is it safe?
[datawhale202207] reinforcement learning: the foundation of reinforcement learning
Clear wechat applet and wechat H5 cache
What does PK, NN, Qu, B, UN, ZF, AI, G mean when creating tables in MySQL
How to play a data mining game entry Edition
日期(DAY 76)
MySQL index collation summary
Keil uvisin5 code auto completion or code Association
DOM events
C language -c51 compilation warning "* * * warning l1: unresolved external symbol" and extern