引用的执行速度vs指针 [英] Execution speed of references vs pointers

查看:215
本文介绍了引用的执行速度vs指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近阅读了一篇关于托管语言是否比本地语言(特别是C#vs C ++)更慢(或更快)的讨论。一个有助于讨论的人说,托管语言的JIT编译器将能够对引用进行优化,这在使用指针的语言中是不可能的。

I recently read a discussion regarding whether managed languages are slower (or faster) than native languages (specifically C# vs C++). One person that contributed to the discussion said that the JIT compilers of managed languages would be able to make optimizations regarding references that simply isn't possible in languages that use pointers.

我想知道的是什么样的优化是可能的引用而不是指针?

What I'd like to know is what kind of optimizations that are possible on references and not on pointers?

请注意,讨论是关于执行速度,而不是内存使用。

Note that the discussion was about execution speed, not memory usage.

推荐答案

JIT编译在维基百科中提到:


JIT代码通常提供比口译员。此外,它在某些或许多情况下提供比静态编译更好的性能,因为许多优化仅在运行时可行:

JIT code generally offers far better performance than interpreters. In addition, it can in some or many cases offer better performance than static compilation, as many optimizations are only feasible at run-time:


  1. 编译可以优化到目标CPU和应用程序运行的操作系统模型。例如,JIT可以在检测到CPU支持它们时选择SSE2 CPU指令。使用静态编译器,必须编写两个版本的代码,可能使用内联汇编。

  2. 系统能够收集关于程序如何在其所在环境中实际运行的统计信息,并可以重新排列和重新编译以获得最佳性能。

  3. 系统可以进行全局代码优化(例如,库函数的内联),而不会失去动态链接的优点,并且没有固有的开销到静态编译器和链接器。具体来说,当进行全局内联替换时,静态编译器必须插入运行时检查,并确保如果对象的实际类覆盖了内联方法,则会发生虚拟调用。

  4. 可以使用静态编译的垃圾收集语言,一个字节码系统可以更轻松地重新排列内存以更好地利用缓存。

  1. The compilation can be optimized to the targeted CPU and the operating system model where the application runs. For example JIT can choose SSE2 CPU instructions when it detects that the CPU supports them. With a static compiler one must write two versions of the code, possibly using inline assembly.
  2. The system is able to collect statistics about how the program is actually running in the environment it is in, and it can rearrange and recompile for optimum performance. However, some static compilers can also take profile information as input.
  3. The system can do global code optimizations (e.g. inlining of library functions) without losing the advantages of dynamic linking and without the overheads inherent to static compilers and linkers. Specifically, when doing global inline substitutions, a static compiler must insert run-time checks and ensure that a virtual call would occur if the actual class of the object overrides the inlined method.
  4. Although this is possible with statically compiled garbage collected languages, a bytecode system can more easily rearrange memory for better cache utilization.


我不能想到与使用引用而不是指针直接相关的东西。

I can't think of something related directly to the use of references instead of pointers.

这篇关于引用的执行速度vs指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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