“收益率0"与“收益率0"之间有什么区别?和"yield return null".在协程中?

“收益率0

问题描述:

我是新手,对"yield"有点困惑.但是最后我了解了如何使用WaitForSeconds

I'm new and a bit confused about "yield". But finally I understand how it worked using WaitForSeconds

但是我看不到"yield return 0"和"yield return null"之间的区别.

but I can't see the difference between of "yield return 0" and "yield return null".

他们都在等待下一帧执行吗?

are both them waiting for the next frame to execute?

对不起,我的英语不好.非常感谢.

sorry for my bad English. Thank you very much.

yield return 0yield return null都产生单个帧.最大的区别是yield return 0分配内存是因为0在装箱过程中发生装箱和拆箱,但是yield return null不会分配内存.因此,强烈建议您使用yield return null来关注性能.

Both yield return 0 and yield return null yields for a single frame. The biggest difference is that yield return 0 allocates memory because of boxing and unboxing of the 0 that happens under the hood, but yield return null does not allocate memory. Because of this, it is highly recommended to use yield return null if you care about performance.