哪种数据类型提供更好的性能 [英] which data types provide better performance

查看:67
本文介绍了哪种数据类型提供更好的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.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.


这篇关于哪种数据类型提供更好的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆