c# - 为什么多个班级成员分配会产生冗余装配?
问题描述
在玩 C# 时,我遇到了这种“奇怪的行为”。
功能
public static Vec3 f()
{
var v = new Vec3();
v.x = 0;
v.y = 0;
v.z = 0;
v.x = 0;
v.y = 0;
v.z = 0;
v.x = 0;
v.y = 0;
v.z = 0;
return v;
}
当您使用class
关键字 for时Vec3
,asm输出会产生冗余代码:
public class Vec3
{
public int x;
public int y;
public int z;
}
汇编
C.f()
L0000: sub rsp, 0x28
L0004: mov rcx, 0x7ff7aaa5d040
L000e: call 0x00007ff801dba370
L0013: xor edx, edx
L0015: mov [rax+8], edx
L0018: mov [rax+0xc], edx
L001b: mov [rax+0x10], edx
L001e: mov [rax+8], edx ; isn't this redundant?
L0021: mov [rax+0xc], edx ; isn't this redundant?
L0024: mov [rax+0x10], edx ; isn't this redundant?
L0027: mov [rax+8], edx ; isn't this redundant?
L002a: mov [rax+0xc], edx ; isn't this redundant?
L002d: mov [rax+0x10], edx ; isn't this redundant?
L0030: add rsp, 0x28
L0034: ret
但是 whitstruct
关键字我们得到以下输出:
public struct Vec3
{
public int x;
public int y;
public int z;
}
汇编
C.f()
L0000: xor eax, eax
L0002: mov [rcx], eax
L0004: mov [rcx+4], eax
L0007: mov [rcx+8], eax
L000a: mov rax, rcx
L000d: ret
问题
那些装配线不是多余的吗?如果没有,你能解释一下为什么吗?
笔记
我知道class
并且struct
不一样。问题是关于多MOV
条指令。
解决方案
推荐阅读
- flutter - 小部件截断 - Flutter
- javascript - redux 形式的字段规范化
- windows - 如何在 Windows 文件资源管理器中将我的自定义图像文件类型预览为缩略图?
- java - 如何在我的 Android 应用程序中将 Instagram 分享添加到故事按钮
- vue.js - 如何在 VueJS 中有一个作用域切换变量
- python-3.x - 将 CSV 导入 Django,保存数据并在模板中显示结果
- linux - 如何在 bash shell Linux 中使用两个单词查找路径
- terraform - Terraform 后端 SignatureDoesNotMatch
- gps - 参考具有 GPS 纬度和经度的位置的北查找方位
- kubernetes - Terraform Kubernetes 供应商“local-exec” kubectl apply -f -<
我正在尝试通过 Terraform 的 null_resource 将这个 kubectl .yaml 文件时间戳在线转换