哪种数据类型提供更好的性能

编程入门 行业动态 更新时间:2024-10-27 02:18:42
本文介绍了哪种数据类型提供更好的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在.NET中,哪些数据类型提供更好的性能? 值类型 参考类型 指针类型 反身类型

In .NET, which data types provide better performance? Value types Reference types Pointer types Reflexive types

推荐答案

您可以使用正确的数据类型来完成正确的工作,这是您可以期望的最佳性能。 值类型通常在堆栈上运行,因为它们是原始类型,所以它们是高性能。引用类型是复杂类型并在堆上运行,通常它们比原始类型快,但在jit-ing之后它们可以同样快。 除非您使用的是不安全的代码,否则C#不会使用指针类型。性能取决于你正在做什么,它们可以非常快(接近原始)或非常慢,因为系统必须进行内存固定和其他不安全的操作。 反思,我认为你的意思是反映,非常慢,实际上是数量级减慢,因为它们在运行时无法预编译。 You use the proper data type for the proper job and thats the best performance you can hope for. Value types typically operate on the stack and since they are primitive types they are "high performance". Reference types are complex types and operate on the heap, typically they are less fast than primitive types but after jit-ing they can be just as fast. Pointer types are not used by C# unless you are working with unsafe code. The performance depends on what you are doing, they can either be very fast (near primitive) or very slow since the system has to do memory pinning and other unsafe operations. Reflexive, which I think you mean reflected, are very slow, orders of magnitude slow actually because they cannot be precompiled during runtime.

更多推荐

哪种数据类型提供更好的性能

本文发布于:2023-10-19 07:22:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1506783.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:哪种   数据类型   性能

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!