473,382 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Dynamic Arrays

Is there a high performance way in .Net to dynamically build single dimension
arrays when the number of elements in the array is unknown until after the
array is built? (i.e. I only need the array to grow, I don't need to remove
elements)

I noticed that Dim myVar As List(of X) gets converted to Dim myVar() As X
when returned from a web service. I'd like to build a single code base that
supports either using web services (Tiers) or tightly linked assemblies
(Layers). It would appear for that to work I'll need to use Arrays instead
of the new generics.

Thanks,

Larry
Jun 5 '06 #1
4 1119
Larry,
No, there isn't. An array, once created, has a fixed upperBound. You can use
the ArrayList class as an alternative.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Larry Charlton" wrote:
Is there a high performance way in .Net to dynamically build single dimension
arrays when the number of elements in the array is unknown until after the
array is built? (i.e. I only need the array to grow, I don't need to remove
elements)

I noticed that Dim myVar As List(of X) gets converted to Dim myVar() As X
when returned from a web service. I'd like to build a single code base that
supports either using web services (Tiers) or tightly linked assemblies
(Layers). It would appear for that to work I'll need to use Arrays instead
of the new generics.

Thanks,

Larry

Jun 5 '06 #2
the array list uses an array under the covers (just keeps copying to new
bigger ones as items are added), so you want to give it a good hint on the
initial size.

-- bruce (sqlwork.com)

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:94**********************************@microsof t.com...
Larry,
No, there isn't. An array, once created, has a fixed upperBound. You can
use
the ArrayList class as an alternative.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Larry Charlton" wrote:
Is there a high performance way in .Net to dynamically build single
dimension
arrays when the number of elements in the array is unknown until after
the
array is built? (i.e. I only need the array to grow, I don't need to
remove
elements)

I noticed that Dim myVar As List(of X) gets converted to Dim myVar() As X
when returned from a web service. I'd like to build a single code base
that
supports either using web services (Tiers) or tightly linked assemblies
(Layers). It would appear for that to work I'll need to use Arrays
instead
of the new generics.

Thanks,

Larry

Jun 5 '06 #3
On Mon, 5 Jun 2006 11:52:01 -0700, Larry Charlton
<La***********@discussions.microsoft.com> wrote:
Is there a high performance way in .Net to dynamically build single dimension
arrays when the number of elements in the array is unknown until after the
array is built? (i.e. I only need the array to grow, I don't need to remove
elements)

I noticed that Dim myVar As List(of X) gets converted to Dim myVar() As X
when returned from a web service. I'd like to build a single code base that
supports either using web services (Tiers) or tightly linked assemblies
(Layers). It would appear for that to work I'll need to use Arrays instead
of the new generics.

Thanks,

Larry


If you are looking for high performance, you should switch to a
generic List.

List<int> myList = new List<int>();
myList.Add(1);
myList.Add(2);
etc.

When 2.0 came out, I switched from an ArrayList to a Generic List and
saw a 15x improvement in speed. (of course, mileage my vary...)

The reason is because generic's create native types for the CLR to
process. ArrayList's have to box and unbox on every reference. Ouch.

Good luck.
Peter Kellner
http://peterkellner.net
Jun 5 '06 #4
As Peter B. and Peter K. pointed out, an ArrayList or a generic List are
probably better, but be aware that you can resize arrays in .NET.
In .NET 2, you can use Array.Resize to resize single dimension arrays. Be
aware that it does copy the contents to a new array internally on each
'Resize' call. This is the main reason why the alternatives mentioned are
faster.
For multi-dimensional arrays, you can use the approach I discuss here:
http://www.tangiblesoftwaresolutions...20Preserve.htm
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter

"Larry Charlton" wrote:
Is there a high performance way in .Net to dynamically build single dimension
arrays when the number of elements in the array is unknown until after the
array is built? (i.e. I only need the array to grow, I don't need to remove
elements)

I noticed that Dim myVar As List(of X) gets converted to Dim myVar() As X
when returned from a web service. I'd like to build a single code base that
supports either using web services (Tiers) or tightly linked assemblies
(Layers). It would appear for that to work I'll need to use Arrays instead
of the new generics.

Thanks,

Larry

Jun 6 '06 #5

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

Similar topics

4
by: Scott Lyons | last post by:
Hey all, Can someone help me figure out how to pass a dynamic array into a function? Its been giving me some trouble, and my textbook of course doesnt cover the issue. Its probably something...
4
by: learnfpga | last post by:
Here is a little code I wrote to add the numbers input by the user.....I was wondering if its possible to have the same functionality without using dynamic arrays.....just curious..... ...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
4
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
4
by: Sunny | last post by:
Hi, Is there a way in javascript to create Dynamic arrays or arrays on fly. Something Like: var "ptsgN"+sd = new Array(); Here sd is incrementing by 1. I have lots of data that I am...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.