首页 > Windows开发 > 详细

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

时间:2015-12-24 13:21:01      阅读:192      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!