A single Microsoft Windows process that has the CLR loaded into it

本文深入探讨了在加载了CLR的单个Microsoft Windows进程内部,线程堆栈的工作原理以及如何在不同方法间分配内存。通过具体实例展示了方法调用过程中的参数传递和返回地址的管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A singleMicrosoft Windows process that has the CLR loaded into it

 

In this processthere may be many threads.

When athread is created, it is allocated a 1-MB stack.

This stackspace is used for passing arguments to a method and for local variables defined

within amethod. In Figure 4-2, the memory for one thread’sstack is shown (on the right).

Stacks buildfrom high-memory addresses to low-memory addresses.

When the M1 methodstarts to execute, its prologue code allocates memory for the local namevariable

from the thread’s stack (see Figure 4-3).

Then, M1calls the M2 method, passing in the namelocal variable as an argument.

Inside the M2method, the stack location will be identified usingthe parameter variable named s.

Also, when amethod is called, the address

indicatingwhere the called method should return to in the calling method is pushed on the

stack (also shown in Figure4-4).

When the M2method starts to execute, its prologue codeallocates memory for the local

length and tallyvariables from the thread’sstack (see Figure 4-5). Then the code inside

method M2executes. Eventually, M2gets to its return statement, which causes the CPU’s

instructionpointer to be set to the return address in the stack, and M2’s stack frame is unwound

so that itlooks the way it did in Figure 4-3. At this point, M1is continuing to execute

its codethat immediately follows the call to M2, and its stack frame accurately reflects the

state needed by M1.

 

Our Windowsprocess has started, the CLR is loaded into it, the managed heap isinitialized,

and a thread has been created(along with its 1 MB of stack space).

At thistime, the CLR ensures that the assemblies that definethese types are loaded. Then, using the assembly’smetadata, the CLR extracts

informationabout these types and creates some data structures to represent the types

themselves.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值