Does a value type variable change the LIFO type of the stack

I will assign a value to the say value type for example

int i=0;
int j=1;

Since intthis is a variable of type value, the memory is allocated on the stack as follows (press the value i and j for the stack):

|_|<-- stack top
|1|<--j value
|0|<--i value

I have little doubt about this distribution:

  • If I started i+=1at this time, what would be the changes in stack distribution?
  • How can a value be output iwithout inputj
  • If I assign i, then the value will be stored at the top of the stack, at this time what will happen to the previously assigned value:
+4
source share
3

, "". , . stack frame. , . . EBP 32- , RSP 64- . . "" . "" .

, # Stack<object[]>.

.

+2

:

  • # - , .NET CLR .NET .
  • , , .

.NET CLR, , j , , , , , .

LIFO. EBP ESP .

0

.

, . , .

, . .

|                        |
| More stack data        |
|                        |
+------------------------+
| Method return address  |
+------------------------+
| i                      | Stack frame
| j                      |
+------------------------+
<--- stack pointer

bp , [bp + 0] i [bp + 4] j.

, , .

(Note that this is detailed implementation information, and the JIT compiler can, for example, use a register to store a variable instead of space in the stack frame, and when a close appears in the picture, it changes things, but it works as a starting point for understanding how local variables work.)

0
source

Source: https://habr.com/ru/post/1605675/


All Articles