是什么特殊情况的foreach循环,消除边界检查? [英] What is the special case with the foreach loop that eliminates bounds checking?

查看:262
本文介绍了是什么特殊情况的foreach循环,消除边界检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是特例在foreach /循环,消除边界检查?同时它的边界检查是什么呢?

What is the special case with the foreach/for loop that eliminates bounds checking? Also which bounds checking is it?

推荐答案

标准

for(int i = 0; i < array.Length; i++) {
    ...
}

循环是一个允许JIT以安全移除数组的边界检查(该指数是否在[0..length-1])

loop is the one that allows the JIT to safely remove array bounds checks (whether the index is within [0..length-1])

的foreach 遍历数组等同于标准遍历数组。

The foreach loop over arrays is equivalent to that standard for loop over arrays.

编辑: 正如罗伯特·杰普逊所指出的:

As Robert Jeppesen points out:

如果阵列是这将被优化   本地。如果数组是访问   其他位置,边界检查会   仍然进行。参考:<一href="http://blogs.msdn.com/b/clr$c$cgeneration/archive/2009/08/13/array-bounds-check-elimination-in-the-clr.aspx"相对=nofollow称号=MSDN博客&GT; JIT,NGEN,和c代的东西&GT等管理$ C $;数组边界检查消除在CLR>数组边界检查消除在CLR

This will be optimized if the array is local. If the array is accessible from other locations, bounds checking will still be performed. Reference: Array Bounds Check Elimination in the CLR

谢谢!不知道我自己。

这篇关于是什么特殊情况的foreach循环,消除边界检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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