当前位置:网站首页>Bottom processing of stack memory in browser
Bottom processing of stack memory in browser
2022-04-23 16:58:00 【Endless cake】
Execution stack
JS The engine wants to execute code , An execution stack will be created , That's what we call :
Stack memory (ECstackl) Execution context stack
The first function of stack memory :
Used to execute code
JS in , Code execution under a domain , Each has its own execution context . Compress the created execution context to js This process is performed in stack memory in , There is a professional term : Into the stack
Created execution context , There are two kinds of :
overall situation EC(G) there G refer to global Abbreviation
function EC (…)
When some context is executed , It's useless. . We call it : Out of the stack .
However , Some ask up and down after the execution , It's also useful , Will compress it to the bottom of the stack , Wait for the next call ,( That is, the top and bottom questions have not been destroyed ), This mechanism also has a professional term called : Closure
Inside this , It also involves a professional term called global object (GO) globla obeject On the browser side , Will assign the global object to window . All in our global execution context , It must contain GO( Global object )
The second function of stack memory
Store basic type values ( For example, global object, we create a variable , Will be stored in the stack )
There is a very important concept , Look at the example
let a = 10;
// This variable will be stored in the stack by us
We define a variable, which is very simple , So let's see , How does he realize the assignment and creation of variables .
The assignment of all variables is divided into three steps to create ( If it has been created, it will not be created again )
Three step operation of variable assignment :
(1) Create variables ( Statement declare)
(2) Create values : The basic values can be directly created and stored in the stack memory
(3) Associate variables with values ( assignment ) defined Definition
therefore , We usually only declare variables, but if we don't define them ,js You're going to report a mistake undefined ( Undefined )
let a = 10;
let b =a;
This is the time , Let's create another variable b, because b=a,a Has been created . So you don't have to create values anymore , Just associate ,b=a Will go through it directly Pointer to a Value , That is to say 10. therefore b be equal to 10
Here I mentioned an important concept , The pointer . In fact, the underlying data processing mechanism of programming language , Pointer to variable , Are implemented through pointers . The concept of pointer is , The association of a variable with a value , It's called Association The pointer .
let a = 10;
let b =a;
b = 13;
This is the time , We assign b=13, This is the time b Has been declared . So there is no need to restate , This is to prevent the browser from redefining A process of . Then you need to create a new value 13, Put it in the stack ( therefore , As long as this mechanism is followed , Values will be created , Even if the value is the same )
js A variable in can only point to one value , Yes b Reassign , It doesn't affect a Of . therefore ,b=13, that a Is equal to 10.
A digression , Namely js in , There are two ways to define values , You can define variables and constants
The essential difference between variables and constants is , The direction of the variable can be changed , And constant , Each value is separate . The pointer cannot be changed , If you change, you will report an error .
ES6 In the const, It's not called a real constant , Its specialized syntax is called immutable variables , Or a variable whose pointer cannot be changed .
Create reference types
let a = {
n:12
}
let b = a;
b['n'] = 13;
console.log(a.n)
The creation of reference values is different , Because reference values are complex deconstructions , So special treatment .
Handle reference values :
(1) Open up a key value pair in the storage object ( Store the code in the function ) Of memory space , Namely “ Heap memory ”.
So heap memory has only one function , Store values of reference types .
(2) All heap memory has one that can be searched later 16 Base address
(3) So when assigning values to subsequent associations , Is to give the heap memory address to the variable operation .
That's why we call it a reference type , Because it operates on reference addresses .
Back to the example above , adopt b[‘n’] = 13 It will directly affect a.n Value , because a and b Bound is an address .
Reference type operation
let a = {
n:12
}
let b = a;
b={
n:13
}
console.log(a.n)
Because it's the reference type , So it must have recreated a heap .
a The heap address of is equal to a1.
then b be equal to a, therefore b The heap address of is also equal to a1
b={} therefore b Recreated a reference value , And generates a new heap b1. This is the time b The point is b1.
This is the time ,a and b All have their own direction , therefore a.n be equal to 12.
Knowledge point : Once heap memory is created , Can't be destroyed . If you want to destroy, you can make the reference type directly equal to null.
null: An empty object . By pointing the pointer to a null pointer , To release some memory .
On a daily basis , We define a variable , If you want to assign a value later , We define its value as null. Because if you only declare , If you don't create a value, it will be equal to undefined. I've seen a lot of people who are equal to 0 Of , In fact, this operation is not recommended , Because it is equal to 0, It will also open memory in the stack . and null It doesn't open memory .
版权声明
本文为[Endless cake]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230554520092.html
边栏推荐
- MySQL modify master database
- Log4j output log information to file
- freeCodeCamp----shape_ Calculator exercise
- PyMySQL
- 昆腾全双工数字无线收发芯片KT1605/KT1606/KT1607/KT1608适用对讲机方案
- Shell script -- shell programming specification and variables
- Encapsulating the logging module
- 无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
- Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme
- Detailed explanation of file operation (2)
猜你喜欢
groutine
The new MySQL table has a self increasing ID of 20 bits. The reason is
Nacos + aspnetcore + Ocelot actual combat code
Path environment variable
On lambda powertools typescript
PyTorch:train模式与eval模式的那些坑
Detailed explanation of file operation (2)
Loggie source code analysis source file module backbone analysis
Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme
Use case execution of robot framework
随机推荐
websocket
【PIMF】OpenHarmony啃论文俱乐部—在ACM Survey闲逛是什么体验
Pycham connects to the remote server and realizes remote debugging
TypeError: set_ figure_ params() got an unexpected keyword argument ‘figsize‘
Read a blog, re understand closures and tidy up
Knowledge points and examples of [seven input / output systems]
Get the column name list of the table quickly in Oracle
Freecodecamp ---- budget & category exercise
Detailed explanation of UWA pipeline function | visual configuration automatic test
Shortcut keys (multiline)
Nifi fast installation and file synchronization
Calculation formula related to tolerance analysis
Website_ Collection
Detailed explanation of the penetration of network security in the shooting range
Mock test using postman
Rtklib 2.4.3 source code Notes
New keyword learning and summary
Generate random numbers with high quality and Gaussian distribution
Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme
PHP efficiently reads large files and processes data