拳击问题 [英] Boxing Question

查看:79
本文介绍了拳击问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,这可能会大大受益于使用结构代替

类。但是,它需要足够丰富才能有方法

可用。


我的问题是 - 每次在结构上调用方法时,是吗?盒装?

因为那将是一个巨大的性能。


我假设它必须装箱,但如果有人知道肯定的话/>
这将是伟大的!

I am writing an app that might largely benefit from using a struct instead
of a class. However, it needs to be rich enough where there are methods
available.

My question is - every time you call a method on a struct, is it boxed?
Because that would be a huge perf hit.

I am assuming that it does have to be boxed, but if anyone knows for sure
that would be great!

推荐答案

Nathan,
Nathan,
我正在写一个应用程序可能在很大程度上受益于使用结构而不是类。


为什么?


我的问题是 - 每次在结构上调用方法时,是否装箱?
I am writing an app that might largely benefit from using a struct instead
of a class.
Why?

My question is - every time you call a method on a struct, is it boxed?







Mattias


-

Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net / dotnet / | http://www.dotnetinterop.com

请回复到新闻组。



No

Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


嗨Nathan,
Hi Nathan,
我正在编写一个应用程序,可能会大大受益于使用结构而不是

很少或根本没有性能理由偏好结构类,

很少或没有效率原因,很少或没有可读性原因。 />
结构对于对非托管代码进行API调用很有用。


结构仅在最少的情况下有用,并且个人,

我从未在非托管API调用之外的C#中使用过它们。事实上,我已经在他已经监督过的系统中提供的成千上万行代码中使用了
甚至_seen_。 ,b $ b参加了。


-

--- Nick Malik [微软]

MCSD,CFPS,认证Scrummaster
http://blogs.msdn.com / nickmalik


免责声明:本论坛中表达的意见是我自己的意见,而不是我雇主的b $ b代表。

我不代表我的雇主回答问题。我只是一个帮助程序员的
程序员。

-

" Nathan Neitzke" <是ne ****** @ erau.edu>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...

然而,在有可用方法的地方,它需要足够丰富。

我的问题是 - 每次你在一个结构上调用一个方法时,它是否装箱?
因为那将是一个巨大的性能。

我假设它必须装箱,但如果有人确切知道
那就太棒了!
I am writing an app that might largely benefit from using a struct instead
of a class.
There is little or no performance reason to prefer a struct over a class,
little or no efficiency reason, and little or no readability reason.
Structs are useful for making API calls to unmanaged code.

Structs are useful in only the smallest number of cases, and personally,
I''ve never used them in C# outside of unmanaged API calls. In fact, I''ve
never even _seen_ them used in the hundreds of thousands of lines of code
that have been delivered in the systems that I''ve overseen, reviewed, or
participated in.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I''m just a
programmer helping programmers.
--
"Nathan Neitzke" <ne******@erau.edu> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
However, it needs to be rich enough where there are methods available.

My question is - every time you call a method on a struct, is it boxed?
Because that would be a huge perf hit.

I am assuming that it does have to be boxed, but if anyone knows for sure
that would be great!


>很少或没有性能理由偏好结构而不是
类,
>There is little or no performance reason to prefer a struct over a
class,
很少或没有效率原因




如果我错了,请纠正我,但托管代码中的结构/值类型是

主要是为了提高性能。如果你有大量的数据,那么在堆栈上创建它的价格要比在堆上的b
便宜得多。


我个人从来没有在我的代码中使用过结构(这实际上并不是很好)但是我一直在寻找一些理由来证明它仅仅来自于b $ b绩效观点。我总是想念那些大量物品正在获得的物品

分配/解除分配是使用价值类型的驱动力
$ b托管代码$ b。


---------

Ajay Kalra
aj ******* @ yahoo.com



Correct me if I am wrong, but struct/value type in managed code is
mainly to improve performance. If you have large amount of data,
creating it on the stack is considerably less expensive than going on
the heap.

I have personally never used structs in my code (which is not really
saying much) but I have always been looking for some reason which will
justify it based solely from performance point of view. I have always
thought of the sceanrio where a large number of objects are getting
allocated/deallocated to be the driving force behind using a value type
in managed code.

---------
Ajay Kalra
aj*******@yahoo.com


这篇关于拳击问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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