CLR 中的堆栈管理

发布于 2024-10-20 04:57:42 字数 212 浏览 4 评论 0原文

我了解堆栈和堆的基本概念,但如果有任何1可以解决以下困惑,那就太好了:

  1. 整个应用程序进程是否有一个堆栈,或者为项目中启动的每个线程创建一个新堆栈?

  2. 是否有一个堆用于整个应用程序进程或为项目中启动的每个线程创建一个新堆栈?

  3. 如果为每个线程创建堆栈,那么进程如何管理线程的顺序流(以及堆栈)

I understand the basic concept of stack and heap but great if any1 can solve following confusions:

  1. Is there a single stack for entire application process or for each thread starting in a project a new stack is created?

  2. Is there a single Heap for entire application process or for each thread starting in a project a new stack is created?

  3. If Stack are created for each thread, then how process manage sequential flow of threads (and hence stacks)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不知在何时 2024-10-27 04:57:42
  1. 每个线程都有一个单独的堆栈。这不仅适用于 CLR,也不仅适用于 Windows,而且几乎适用于每个操作系统或平台。

  2. 每个应用程序域都有一个堆。单个进程可以同时运行多个应用程序域。单个应用程序域可以运行多个线程。
    更准确地说,每个域通常有两个堆:一个是常规堆,另一个用于非常大的对象(例如,64K 数组)。

  3. 我不明白你所说的“线程顺序流”是什么意思。

  1. There is a separate stack for every thread. This is true not only for CLR, and not only for Windows, but pretty much for every OS or platform out there.

  2. There is single heap for every Application Domain. A single process may run several app domains at once. A single app domain may run several threads.
    To be more precise, there are usually two heaps per domain: one regular and one for really large objects (like, say, a 64K array).

  3. I don't understand what you mean by "sequential flow of threads".

颜漓半夏 2024-10-27 04:57:42

每个线程一个堆栈,所有线程共享相同的堆。

不存在线程的“顺序流”。线程是存储处理器状态副本的操作系统对象。处理器状态包括寄存器值。其中之一是 ESP,堆栈指针。另一个非常重要的是 EIP,即指令指针。当操作系统在线程之间切换时,它将处理器状态存储在当前线程对象中,并从线程对象中为选择下一个运行的线程重新加载状态。处理器现在只是继续执行之前停止的地方。

启动一个线程现在也许也很容易理解。操作系统为堆栈分配一兆字节的内存。并初始化 ESP 寄存器值以指向该内存。并将EIP寄存器的值设置为线程应开始执行的方法的地址。 C# 中 ThreadStart 委托的值。

One stack for each thread, all threads share the same heaps.

There is no 'sequential flow' of threads. A thread is an operating system object that stores a copy of the processor state. The processor state includes the register values. One of them is ESP, the stack pointer. Another really important one is EIP, the instruction pointer. When the operating system switches between threads, it stores the processor state in the current thread object and reloads the state from the thread object for the thread that was selected to run next. The processor now simply continues executing where it left off previously.

Getting a thread started is perhaps now easy to understand as well. The operating system allocates a megabyte of memory for the stack. And initializes the ESP register value to point to that memory. And sets the value of the EIP register to the address of the method where the thread should start executing. The value of the ThreadStart delegate in C#.

套路撩心 2024-10-27 04:57:42

每个线程必须有自己的堆栈,这是保存局部变量和参数以及先前函数的返回地址的地方。

Each thread must have it's own stack, that's where local variables and parameters are held, and the return addresses of the previous functions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文