473,702 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList without Boxing and UnBoxing

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.
Nov 3 '06 #1
94 5668


"Peter Olcott" <No****@SeeScre en.comwrote in message
news:ho******** ***********@new sfe19.lga...
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.
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
Nov 3 '06 #2

Peter Olcott wrote:
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. 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.

Nov 3 '06 #3
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 StringCollectio n and
StringDictionar y in the System.Collecti ons.Specialized namespace.
http://msdn2.microsoft.com/en-gb/lib...80,en-us).aspx
On Nov 3, 11:03 am, "Peter Olcott" <NoS...@SeeScre en.comwrote:
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.
Nov 3 '06 #4
Those are good links, Bill, but they don't address the OP's problem.

Remember that the original question was how to avoid boxing and
unboxing. Any collection that derives from CollectionBase will store
Object, and so require boxing and unboxing for value types.

The only way to avoid boxing overhead is to write your own collection
class that wraps an array of the value type in question. However,
before going down that road, it's important to determine that boxing is
indeed a problem.

Bill Rodenbaugh wrote:
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 StringCollectio n and
StringDictionar y in the System.Collecti ons.Specialized namespace.
http://msdn2.microsoft.com/en-gb/lib...80,en-us).aspx
On Nov 3, 11:03 am, "Peter Olcott" <NoS...@SeeScre en.comwrote:
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.
Nov 3 '06 #5

"Bruce Wood" <br*******@cana da.comwrote in message
news:11******** *************@m 73g2000cwd.goog legroups.com...
Those are good links, Bill, but they don't address the OP's problem.

Remember that the original question was how to avoid boxing and
unboxing. Any collection that derives from CollectionBase will store
Object, and so require boxing and unboxing for value types.

The only way to avoid boxing overhead is to write your own collection
class that wraps an array of the value type in question. However,
before going down that road, it's important to determine that boxing is
indeed a problem.
My response time can not exceed 1/10 second. The class is currently implemented
in C++ using std::vector. I can not afford any degradation in the performance of
this class when ported to .NET.
>
Bill Rodenbaugh wrote:
>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 StringCollectio n and
StringDictiona ry in the System.Collecti ons.Specialized namespace.
http://msdn2.microsoft.com/en-gb/lib...80,en-us).aspx
On Nov 3, 11:03 am, "Peter Olcott" <NoS...@SeeScre en.comwrote:
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.

Nov 3 '06 #6
Peter Olcott wrote:
"Bruce Wood" <br*******@cana da.comwrote in message
news:11******** *************@m 73g2000cwd.goog legroups.com...
>>
Remember that the original question was how to avoid boxing and
unboxing. Any collection that derives from CollectionBase will store
Object, and so require boxing and unboxing for value types.

The only way to avoid boxing overhead is to write your own collection
class that wraps an array of the value type in question. However,
before going down that road, it's important to determine that boxing is
indeed a problem.

My response time can not exceed 1/10 second. The class is currently implemented
in C++ using std::vector. I can not afford any degradation in the performance of
this class when ported to .NET.
You can box and unbox a lot of variables before it is noticeable in
1/10 second time intervals.

Arne
Nov 3 '06 #7

Peter Olcott wrote:
"Bruce Wood" <br*******@cana da.comwrote in message
news:11******** *************@m 73g2000cwd.goog legroups.com...
Those are good links, Bill, but they don't address the OP's problem.

Remember that the original question was how to avoid boxing and
unboxing. Any collection that derives from CollectionBase will store
Object, and so require boxing and unboxing for value types.

The only way to avoid boxing overhead is to write your own collection
class that wraps an array of the value type in question. However,
before going down that road, it's important to determine that boxing is
indeed a problem.

My response time can not exceed 1/10 second. The class is currently implemented
in C++ using std::vector. I can not afford any degradation in the performance of
this class when ported to .NET.
Is there a particular reason why you're porting to .NET 1.1? .NET 2.0
is far better.

Nov 3 '06 #8

"Arne Vajhøj" <ar**@vajhoej.d kwrote in message
news:45******** *************** @news.sunsite.d k...
Peter Olcott wrote:
>"Bruce Wood" <br*******@cana da.comwrote in message
news:11******* **************@ m73g2000cwd.goo glegroups.com.. .
>>>
Remember that the original question was how to avoid boxing and
unboxing. Any collection that derives from CollectionBase will store
Object, and so require boxing and unboxing for value types.

The only way to avoid boxing overhead is to write your own collection
class that wraps an array of the value type in question. However,
before going down that road, it's important to determine that boxing is
indeed a problem.

My response time can not exceed 1/10 second. The class is currently
implemented in C++ using std::vector. I can not afford any degradation in the
performance of this class when ported to .NET.

You can box and unbox a lot of variables before it is noticeable in
1/10 second time intervals.

Arne
By what factor does a simple integer comparison in a fixed array of integers to
single integer take longer when boxing an unboxing is adding? (Note the simple
comparision itself takes one machine clock). Even if unboxing takes only one
machine clock, we have now doubled the time required.
Nov 3 '06 #9
"Peter Olcott" <No****@SeeScre en.comwrote in message
news:mF******** **********@news fe24.lga...
>
By what factor does a simple integer comparison in a fixed array of
integers to single integer take longer when boxing an unboxing is adding?
(Note the simple comparision itself takes one machine clock). Even if
unboxing takes only one machine clock, we have now doubled the time
required.
Doubling a tiny amount of time still results in a tiny amount of time. You'd
have to do a proper performance analysis before determining that
boxing/unboxing was significant.

///ark
Nov 3 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7855
by: Kevin | last post by:
Hi All Can someone please tell me the difference between an Array and an ArrayList, and where I would be likely to use one over the other Thanks alot for any help
18
3249
by: Sam | last post by:
Hi All I'm planing to write an application which allows users dynamically add their points (say you can add upto 30,000) and then draw xy graph. Should I use an array for my coordinate point storage and dynamically resize it when there is a new point or should I use ArrayList? Is speed noticable between the two? Regards,
48
4470
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a lot faster with both methods using .NET 1.1, that's why I am pretty sure its a (rather serious) bug. Below you can find C# test case that should allow you to reproduce this error, to run it you will need to put 2 data files into current directory...
19
13717
by: ahjiang | last post by:
hi there,, what is the real advantage of boxing and unboxing operations in csharp? tried looking ard the internet but couldnt find any articles on it. appreciate any help
161
7832
by: Peter Olcott | last post by:
According to Troelsen in "C# and the .NET Platform" "Boxing can be formally defined as the process of explicitly converting a value type into a corresponding reference type." I think that my biggest problem with this process is that the terms "value type" and "reference type" mean something entirely different than what they mean on every other platform in every other language. Normally a value type is the actual data itself stored in...
12
9769
by: Justin | last post by:
Ok, I give up. I can't seem to construct a decent (productive) way of sorting my arraylist. I have a structure of two elements: Structure TabStructure Dim TabName As String Dim FullFilePath As String End Structure
0
8652
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9234
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9086
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7829
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4412
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2036
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.