Performance cost of C # value type parameter passing

Source: Internet
Author: User
Performance issues

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


In these situations it is 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, and which may isn't always 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

Performance cost of C # value type parameter passing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.