.NET CIL 代码大小
当查看编译的 CIL 时,我注意到代码大小包含在编译的 CIL 中。它被注释掉了。下面是一个
C# 示例:
static void MakeACar()
{
Car myCar = new Car();
}
CIL:
.method public hidebysig static void MakeAObject() cil managed
{
//Code size 7 (0x7)
.maxstack 1
.locals init ([0] class SimpleGC.Car c)
IL_0000: newobj instance void SimpleGC.Car::.ctor()
IL_0005: stloc.O
IL_0006: ret
}
代码大小代表什么?
When looking at the compiled CIL, I notice the code size is included in the compiled CIL. It is commented out. Below is an example
C#:
static void MakeACar()
{
Car myCar = new Car();
}
CIL:
.method public hidebysig static void MakeAObject() cil managed
{
//Code size 7 (0x7)
.maxstack 1
.locals init ([0] class SimpleGC.Car c)
IL_0000: newobj instance void SimpleGC.Car::.ctor()
IL_0005: stloc.O
IL_0006: ret
}
What does the code size represent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这只是 CIL 字节码形式所占用的字节数。
(看一下您的示例:您可以看到最后一条指令 (
ret
) 从字节偏移 6 (IL_0006:
) 开始。由于ret
被编码为一字节操作码,字节码流最终的总长度为 6 + 1 = 7 字节。)This is just the number of bytes occupied by the CIL in it's bytecode form.
(Take a look at your example: You can see that the last instruction (
ret
) begins at byte offset 6 (IL_0006:
). Sinceret
is encoded as a one-byte opcode, the bytecode stream ends up having a total length of 6 + 1 = 7 bytes.)