locked
The Call Stack - How does it work? RRS feed

  • Question

  • Does each application have its own call stack or does every application use a common .NET call stack?

    Thursday, May 8, 2008 3:30 AM

Answers

  • There is no such thing as a process stack, and there's certainly no distinction between a call stack and a function stack.  Each thread has its own stack, and it doesn't matter if the thread is running native code or managed code.
    Thursday, May 8, 2008 9:57 AM

All replies

  • You can see the managed call stack in the Call Stack window when you run an application in Visual Studio Debug mode.  For example, in a typical WinForms app, you can see that Program.Main() is at the bottom of the stack.  This is usually the entry point of your application.

    So to answer your question, every .NET app has its own managed stack.

    The CLR, which is native code, uses different stacks like process and function stacks, but that is a completely separate topic.

    -Andy
    Thursday, May 8, 2008 4:15 AM
  • OK - thanks for confirming.

     

    I had written an app that, during one point, started an instance of the same process that was located in a different location... so recursive in a way. It resulted in an InvalidOperationException, which I assumed was the result of a stack overflow... even though the app was launching a separate instance of the program and not just infinite recursion inside the program. Hmmm.

     

    Thursday, May 8, 2008 4:46 AM
  • There is no such thing as a process stack, and there's certainly no distinction between a call stack and a function stack.  Each thread has its own stack, and it doesn't matter if the thread is running native code or managed code.
    Thursday, May 8, 2008 9:57 AM
  • Thanks for pointing out those things.  I did some more research to improve my knowledge in this area.  It appears that stack frames can be managed or native; not stacks.  And threads vs. processes is an important distinction.  I didn't mean to spread any misinformation.
    Thursday, May 8, 2008 4:26 PM