unity3d 中尽量避免使用foreach

foreach会消耗掉额外的内存,生成gc alloc,为了压榨手机的最后一部分性能,尽量避免使用foreach。

遍历数组直接使用:

for(int m=0;m<array.length;m++){

// array[m] 操作

}

遍历dictinory使用,这种方式不会造成gc

  • var enumerator = dummyDic.GetEnumerator();
  • while (enumerator.MoveNext()) {
  • // loop body goes here
  • }
发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>