简体   繁体   中英

How to remove a value type from the stack?

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:

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.

any ideas?

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.

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM