码迷,mamicode.com
首页 > Windows程序 > 详细

C#值类型参数传递的性能开销

时间:2015-12-24 13:21:40      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

Performance issues

Let‘s dig a little deeper. When data is passed into methods as value type parameters, a copy of each parameter is created on the stack. Clearly, if the parameter in question is a large data type, such as a user-defined structure with many elements, or the method is executed many times, this may have an impact on performance.


In these situations it may be preferable to pass a reference to the type, using the ref keyword. This is the C# equivalent of the C++ technique of passing a pointer to a variable into a function. As with the C++ version, the method has the ability to change the contents of the variable, which may not always be safe. The programmer needs to decide on the trade-off between security and performance.

 

https://msdn.microsoft.com/en-us/library/4d43ts61(v=vs.90).aspx

C#值类型参数传递的性能开销

标签:

原文地址:http://www.cnblogs.com/lilei9110/p/5072665.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!