locked
Why we should use stack? Is it mandatory for us to use it? RRS feed

  • Question

  • User-552477072 posted

    While I was learning MSIL for debugging my C# .NET applications.

    The question always came to me “why we should use stack?” 

    Want to get some ideas: Why is there a transfer from memory to stack or "loading?" On the other hand, why is there a transfer from stack to memory or "storing"? Why not just place all in the memory?  

    Is it because it is faster? or, Is it that it based on RAM?

    Alternatively, for efficiency?

     I am trying to seize this to help myself to understand CIL codes in deep.

    Thursday, November 29, 2018 3:18 AM

Answers

  • User-474980206 posted
    Stacks are just allocated memory. Stacks are typically used to pass parameters and return address to method calls. This allows nested calls and recursion. iL code uses stack frames so that error unwinds can be done.

    RISC machine may have 100s of registers, that can be accessed in blocks similar to stacks, but only allow limited nesting before a stack is required.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 29, 2018 3:53 AM

All replies

  • User-474980206 posted
    Stacks are just allocated memory. Stacks are typically used to pass parameters and return address to method calls. This allows nested calls and recursion. iL code uses stack frames so that error unwinds can be done.

    RISC machine may have 100s of registers, that can be accessed in blocks similar to stacks, but only allow limited nesting before a stack is required.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 29, 2018 3:53 AM
  • User-552477072 posted

    @bruce Great. That’s exactly what I was looking for. Thanks for the time

    Thursday, November 29, 2018 6:02 AM