In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to solve the structural performance problems in C# 7.2". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In some cases where the readonly keyword is used, the C # compiler creates a defensive copy of the structure. Although this issue is well known and documented, it is still worth re-examining because it is related to several features of C# 7.2. The use of the in and ref readonly keywords makes this problem more frequent, and the readonly structure provides a solution.
Structures in C # are often used to improve performance and reduce the overhead of allocating and destroying memory. However, potential traps limit their use. C # 7.2 has added an improved readonly structure to solve this problem.
The C# compiler creates a copy of the structure in the following cases:
Structures are not read-only.
The mechanism argument uses the readonly modifier.
Call methods (including properties).
The same rules apply when x is the result of an in parameter, a ref readonly local variable, or a method call that returns a value through readonly reference.
The public void BadFunction (in SomeStruct s) {s.X; / compiler creates a defensive copy. }
C # 7.2 increases the possibility of declaring readonly structures and provides a solution to avoid creating defensive copies. Structs declared as readonly cannot have property setters and cannot assign values to struct members.
We can detect defensive copy problems through static analysis. ErrorProne.NET is inspired by ErrorProne, a Java static analysis tool. The version migrated to .NET consists of a set of Roslyn parsers that focus on accuracy and performance. Some of these parsers are suitable for structures and are available for download in the form of Nuget packages.
This is the end of the content of "how to solve the structural performance problems in C# 7.2". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.