C# 内存理论与实践
2024-08-25 15:04:45
The C# Memory Model in Theory and Practice
Best Practices
- All code you write should rely only on the guarantees made by the ECMA C# specification, and not on any of the implementation details explained in this article.
- Avoid unnecessary use of volatile fields. Most of the time, locks or concurrent collections (System.Collections.Concurrent.*) are more appropriate for exchanging data between threads. In some cases, volatile fields can be used to optimize concurrent code, but you should use performance measurements to validate that the benefit outweighs the extra complexity.
- Instead of implementing the lazy initialization pattern yourself using a volatile field, use the System.Lazy<T> and System.Threading.LazyInitializer types.
- Avoid polling loops. Often, you can use a BlockingCollection<T>, Monitor.Wait/Pulse, events or asynchronous programming instead of a polling loop.
- Whenever possible, use the standard .NET concurrency primitives instead of implementing equivalent functionality yourself.
最新文章
- (转)RVA-相对虚拟地址解释
- HDU 5651 计算回文串个数问题(有重复的全排列、乘法逆元、费马小定理)
- SQL 常见函数使用
- java 关键字 transient
- Linux/Unix笔记本
- 【CITE】C#入门学习-----简单画图程序
- Steam和Byte[]之间进行输换
- java编程思想第四版中 net.mindview.util包
- PL/SQL 如何导出INSERT语句
- erl0005 - mnesia 分布式部署
- Seven Python Tools All Data Scientists Should Know How to Use
- 报错java.net.SocketException: Software caused connection abort: recv failed 怎么办
- SSRS 请求并显示SharePoint人员和组字段
- npm 常用命令详解[转]
- Javascript面向对象研究心得
- Android的JunitTest
- 使用charles抓取htpps的方法
- Centos6.8 安装tomcat8.5.11
- SpringBoot 整合Ehcache3
- 计算机信息系统安全保护等级划分准则(GB 17859-1999)