C#优化器是否执行复制省略? [英] Do C# optimizers perform copy elision?

查看:79
本文介绍了C#优化器是否执行复制省略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻求优化一些C#代码,并且很好奇我的优化器是否要执行任何复制省略号,如果是这样的话.我一直无法通过谷歌搜索找到任何信息.如果不是,我可能想切换我的方法以通过引用接受struct参数.我关心的环境是Unity 3D,这很奇怪,因为它使用了Mono 2.0 Runtime或Unity的

I'm looking to optimize some C# code and I'm curious if my optimizer is going to perform any copy elision, and if so which kinds. I haven't been able to find any information on this by googling. If not I may want to switch my methods to take struct arguments by reference. The environment I care about is Unity 3D, which is odd as it uses either the Mono 2.0 Runtime or Unity's IL2CPP transpiler (which I should probably ask them about directly as it's closed-source.) But it would be interesting to know for Microsoft's optimizer as well, and if this type of optimization is generally allowed by the standard.

侧面说明:如果优化程序不支持此功能,那么如果我可以得到等效的C ++ const ref

Side note: If this is not supported by the optimizer, it would be awfully nice if I could get the equivalent of the C++ const ref, but it appears this doesn't exist.

推荐答案

我可以说IL2CPP,并说它对引用结构参数毫无用处.即使没有访问IL2CPP源代码,您也可以通过检查生成的C ++代码来查看.

I can speak for IL2CPP, and say that it does not do anything to take struct arguments by reference. Even without access to the IL2CPP source code, you can see this by inspecting the generated C++ code.

请注意,C#结构由C ++结构表示,并且C ++结构按值传递.我们已经讨论了在这种情况下使用const引用的可能性,但是我们尚未实现(而且可能永远不会实现).

Note that a C# struct is represented by a C++ struct, and that C++ struct is passed by value. We've discussed the possibility of using const references in this case, but we've not implemented yet (and we may not ever).

这篇关于C#优化器是否执行复制省略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆