ArrayList没有Boxing和UnBoxing [英] ArrayList without Boxing and UnBoxing
问题描述
如何在旧版本的.NET中创建一个不需要昂贵的Boxing和UnBoxing操作的
的ArrayList?
在我的情况下它将是一个序列类型结构的ArrayList。
谢谢。
How can I create an ArrayList in the older version of .NET that does not require
the expensive Boxing and UnBoxing operations?
In my case it will be an ArrayList of structures of ordinal types.
Thanks.
推荐答案
" Peter Olcott" < No **** @ SeeScreen.com写在留言中
新闻:ho ******************* @ newsfe19.lga ...
"Peter Olcott" <No****@SeeScreen.comwrote in message
news:ho*******************@newsfe19.lga...
如何在旧版本的.NET中创建一个没有
需要昂贵的Boxing和UnBoxing操作的ArrayList? />
在我的例子中,它将是一个序列类型结构的ArrayList。
谢谢。
How can I create an ArrayList in the older version of .NET that does not
require the expensive Boxing and UnBoxing operations?
In my case it will be an ArrayList of structures of ordinal types.
Thanks.
您需要自己创建一个集合类并实现
必要的方法/属性(包括IEnumerable)。为避免装箱,内部
实现需要是你的
值类型值的数组。 (MyStructure [] mArray)。你还需要实现自己对数组添加和删除的处理(注意:
可能想要创建一个足够大的数组来处理最常见的大小
或最常见的最大尺寸)并且仅在内部阵列中耗尽
元素时增加尺寸。
HTH ,
Mythran
You would need to create a collection class yourself and implement the
necessary methods/properties (including IEnumerable). The internal
implementation, to avoid boxing, would need to be an array of your
value-type values. (MyStructure[] mArray). You would also need to
implement your own handling of adding and removing from the array (note:
probably want to create an array large enough to handle the most common size
or most common maximum size) and only increase the size when you run out of
elements in the internal array.
HTH,
Mythran
Peter Olcott写道:
Peter Olcott wrote:
如何在旧版本的.NET中创建一个不需要昂贵的Boxing和UnBoxing操作的
的ArrayList?
在我的情况下它将是序数类型结构的ArrayList。
How can I create an ArrayList in the older version of .NET that does not require
the expensive Boxing and UnBoxing operations?
In my case it will be an ArrayList of structures of ordinal types.
1.您是否确定拳击和拆箱事实上导致您的应用程序性能显着降低?b $ b也就是说,你试图优化先验,或者你已经有一个你试图解决的性能问题吗?
/ >
2.它必须是一个ArrayList吗?或者你可以使用数组吗?你需要动态添加/删除项目吗?
如果确实有拳击造成的性能问题和
拆箱,你需要一个动态的结构,然后你必须自己建立
。
1. Have you determined that boxing and unboxing are in fact causing
significant performance degradation in your application? That is, are
you trying to optimize a priori, or do you already have a performance
problem you''re trying to resolve?
2. Does it have to be an ArrayList? Or can you use an array? Do you
need to dynamically add / remove items?
If you do indeed have a performance problem caused by boxing and
unboxing, and you need a dynamic structure, then you''ll have to build
your own.
你是什么描述称为强类型集合。
http: //www.google.com/search?q=stron...ed+collections
您应该能够找到一些免费的插件, make
创建它们很容易。
http://www.google.com/search?q=stron...lection+add-in
如果你是处理字符串你可以在System.Collections.Specialized命名空间中使用StringCollection和
StringDictionary。
http://msdn2.microsoft.com/en-gb /lib...80,en-us).aspx
11月3日上午11:03,Peter Olcott < NoS ... @ SeeScreen.comwrote:
What you are describing is called a Strongly Typed Collection.
http://www.google.com/search?q=stron...ed+collections
You should be able to find a number of free add-ins that will make
creating them alot easier.
http://www.google.com/search?q=stron...lection+add-in
If you are dealing with strings you can use the StringCollection and
StringDictionary in the System.Collections.Specialized namespace.
http://msdn2.microsoft.com/en-gb/lib...80,en-us).aspx
On Nov 3, 11:03 am, "Peter Olcott" <NoS...@SeeScreen.comwrote:
如何在不需要的旧版.NET中创建一个ArrayList
昂贵的Boxing和UnBoxing操作?
在我的情况下,它将是一个序列类型结构的ArrayList。
谢谢。
How can I create an ArrayList in the older version of .NET that does not require
the expensive Boxing and UnBoxing operations?
In my case it will be an ArrayList of structures of ordinal types.
Thanks.
这篇关于ArrayList没有Boxing和UnBoxing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!