如何从堆栈中删除值类型?

时间:2021-10-07 17:11:01

I'm trying to study the details inside CLR and one of the things that might sound obvious to me doesn't fit for me:

我正在尝试研究CLR中的细节,对我来说可能听起来很明显的一件事并不适合我:

How is a value type cleared from the Stack?

如何从堆栈中清除值类型?

I understand the GC clears all heap without an address in the stack but I read it doesn't clear stack assign value type.

我理解GC清除所有堆没有堆栈中的地址但我读它不清除堆栈赋值类型。

any ideas?

2 个解决方案

#1


0  

I don't sure that I understand what you ask, but I'll try to answer and hope it will help.

我不确定我理解你的要求,但我会尽力回答并希望它会有所帮助。

In general, for clear value from stack, there is an operation called pop. So to remove a value of value type or a value of reference type, you popping it. The vice versa is push to add value to stack.

通常,对于堆栈中的清除值,有一个名为pop的操作。因此,要删除值类型的值或引用类型的值,请弹出它。反之亦然是推动为堆栈增加价值。

(I wrote "In general" because it correct to all stack based data structure and not just to CLR stack.)

(我写了“一般”,因为它对所有基于堆栈的数据结构都是正确的,而不仅仅是对CLR堆栈。)

One more thing that you need to understand is, that stack in different from heap, is not collected by compacting the memory region, the stack is block of pre allocated memory and values pushed in and popped out when they are needed.

还需要了解的另一件事是,堆栈与堆不同,不是通过压缩内存区域来收集的,堆栈是预先分配的内存块,并且在需要时将值推入并弹出。

If you want to know the exact details of how the stack memory looks like and is register use etc. you can find some links on google but I don't think that what you are looking for.

如果你想知道堆栈内存的确切细节和注册使用等,你可以在google上找到一些链接,但我不认为你在找什么。

#2


0  

Typically, allocations from the stack are performed by decrementing the value in the stack pointer register. To deallocate a stack location, the stack pointer is incremented. The number of bytes by which to increment or decrement the stack pointer depends on the sizes of variables to be allocated or deallocated, respectively. The JIT compiler emits machine instructions to manipulate the stack pointer as required.

通常,通过递减堆栈指针寄存器中的值来执行来自堆栈的分配。要取消分配堆栈位置,堆栈指针会递增。递增或递减堆栈指针的字节数分别取决于要分配或解除分配的变量的大小。 JIT编译器发出机器指令以根据需要操作堆栈指针。

#1


0  

I don't sure that I understand what you ask, but I'll try to answer and hope it will help.

我不确定我理解你的要求,但我会尽力回答并希望它会有所帮助。

In general, for clear value from stack, there is an operation called pop. So to remove a value of value type or a value of reference type, you popping it. The vice versa is push to add value to stack.

通常,对于堆栈中的清除值,有一个名为pop的操作。因此,要删除值类型的值或引用类型的值,请弹出它。反之亦然是推动为堆栈增加价值。

(I wrote "In general" because it correct to all stack based data structure and not just to CLR stack.)

(我写了“一般”,因为它对所有基于堆栈的数据结构都是正确的,而不仅仅是对CLR堆栈。)

One more thing that you need to understand is, that stack in different from heap, is not collected by compacting the memory region, the stack is block of pre allocated memory and values pushed in and popped out when they are needed.

还需要了解的另一件事是,堆栈与堆不同,不是通过压缩内存区域来收集的,堆栈是预先分配的内存块,并且在需要时将值推入并弹出。

If you want to know the exact details of how the stack memory looks like and is register use etc. you can find some links on google but I don't think that what you are looking for.

如果你想知道堆栈内存的确切细节和注册使用等,你可以在google上找到一些链接,但我不认为你在找什么。

#2


0  

Typically, allocations from the stack are performed by decrementing the value in the stack pointer register. To deallocate a stack location, the stack pointer is incremented. The number of bytes by which to increment or decrement the stack pointer depends on the sizes of variables to be allocated or deallocated, respectively. The JIT compiler emits machine instructions to manipulate the stack pointer as required.

通常,通过递减堆栈指针寄存器中的值来执行来自堆栈的分配。要取消分配堆栈位置,堆栈指针会递增。递增或递减堆栈指针的字节数分别取决于要分配或解除分配的变量的大小。 JIT编译器发出机器指令以根据需要操作堆栈指针。