473,897 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array or ArrayList

Sam
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,

Sam
Nov 29 '05 #1
18 3264
I would use an arraylist or possibly even a hashtable. I have only found
problems with "dynamicall y resizing" regular arrays.

Curtis

"Sam" <qd*@datawave.c om> wrote in message
news:Ou******** ******@tk2msftn gp13.phx.gbl...
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,

Sam

Nov 29 '05 #2
"Sam" <qd*@datawave.c om> schrieb:
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?


Use an arraylist or a strongly-typed collection (see class 'DictionaryBase ',
or 'List(Of T)' in .NET 2.0). When using arrays you'd have to redimension
the array every time an item is added using 'ReDim Preserve', which would
internally create a new array and then copy over the data from the existing
array to the new array, which is a very costly process.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 29 '05 #3
Sam
Is there any advantage of using collectionbase class over the arraylist
class to store my custom point structure if I don't need all the fancy stuff
from arraylist class? I saw some sample codes using collectionbase for
storage in stead of arraylist. Does anyone know any good reasons?

Regards

Sam

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
"Sam" <qd*@datawave.c om> schrieb:
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?


Use an arraylist or a strongly-typed collection (see class
'DictionaryBase ', or 'List(Of T)' in .NET 2.0). When using arrays you'd
have to redimension the array every time an item is added using 'ReDim
Preserve', which would internally create a new array and then copy over
the data from the existing array to the new array, which is a very costly
process.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 29 '05 #4
Sam,

"Sam" <qd*@datawave.c om> schrieb:
Is there any advantage of using collectionbase class over the arraylist
class to store my custom point structure if I don't need all the fancy
stuff from arraylist class? I saw some sample codes using collectionbase
for storage in stead of arraylist. Does anyone know any good reasons?


The main reason to use a collection derived from 'CollectionBase ' (sorry for
pointing you to 'DictionaryBase ' erroneously) instead of the 'ArrayList'
class is type-safety. 'ArrayList' can store objects of arbitrary types
while a custom collection can be implemented to accept items of a certain
type only. By typing the return values additional casts become obsolete:

\\\
Dim a As New ArrayList()
....
Dim x As X = DirectCast(a(10 ), X)
///

- opposed to -

\\\
Dim a As New XCollection()
....
Dim x As X = a(10)
///

However, note that inheriting from 'CollectionBase ' requires a lot of code
to be written. If you are storing strings only, consider using the
'StringCollecti on' class instead of an arraylist or a custom collection.
When using .NET 2.0, it's much easier to use 'List(Of T)', which is a
generic class that can be parameterized with the type of the items stored in
the list:

\\\
Dim a As New List(Of X)
....
Dim x As X = a(10)
///

Hope that helps!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 30 '05 #5
Not sure but I think the fastest would be to dim an array of structures where
the structure has an x and y. Initially dimension the array to the maximum
size you will need then count the number of entries. After the data has been
added, you can redim preserve the array to exact number of entries that you
counted.
--
Dennis in Houston
"Sam" wrote:
Is there any advantage of using collectionbase class over the arraylist
class to store my custom point structure if I don't need all the fancy stuff
from arraylist class? I saw some sample codes using collectionbase for
storage in stead of arraylist. Does anyone know any good reasons?

Regards

Sam

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
"Sam" <qd*@datawave.c om> schrieb:
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?


Use an arraylist or a strongly-typed collection (see class
'DictionaryBase ', or 'List(Of T)' in .NET 2.0). When using arrays you'd
have to redimension the array every time an item is added using 'ReDim
Preserve', which would internally create a new array and then copy over
the data from the existing array to the new array, which is a very costly
process.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Nov 30 '05 #6
Sam
Thanks Herfried, you are my big helper. In term of processing, does
collectionbase derived class have significant speed improvement over the
arraylist class?

Sam
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:uo******** ******@TK2MSFTN GP15.phx.gbl...
Sam,

"Sam" <qd*@datawave.c om> schrieb:
Is there any advantage of using collectionbase class over the arraylist
class to store my custom point structure if I don't need all the fancy
stuff from arraylist class? I saw some sample codes using collectionbase
for storage in stead of arraylist. Does anyone know any good reasons?


The main reason to use a collection derived from 'CollectionBase ' (sorry
for pointing you to 'DictionaryBase ' erroneously) instead of the
'ArrayList' class is type-safety. 'ArrayList' can store objects of
arbitrary types while a custom collection can be implemented to accept
items of a certain type only. By typing the return values additional
casts become obsolete:

\\\
Dim a As New ArrayList()
...
Dim x As X = DirectCast(a(10 ), X)
///

- opposed to -

\\\
Dim a As New XCollection()
...
Dim x As X = a(10)
///

However, note that inheriting from 'CollectionBase ' requires a lot of code
to be written. If you are storing strings only, consider using the
'StringCollecti on' class instead of an arraylist or a custom collection.
When using .NET 2.0, it's much easier to use 'List(Of T)', which is a
generic class that can be parameterized with the type of the items stored
in the list:

\\\
Dim a As New List(Of X)
...
Dim x As X = a(10)
///

Hope that helps!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 30 '05 #7
Sam,

"Sam" <qd*@datawave.c om> schrieb:
In term of processing, does collectionbase derived class have
significant speed improvement over the arraylist class?


I do not think it does. So, I'd only roll out my own collection classes
when exposing collections by a class library, for example, as the .NET
Framework does with 'TreeNodeCollec tion' et al. If the collection is only
used inside a method's body (thus an implementation detail which is totally
transparent to the client using your classes), I'd stick with the arraylist
in most cases in .NET 1.0/1.1, or 'List(Of T)' in .NET 2.0 respectively.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 30 '05 #8
Sam,
| In term of processing, does
| collectionbase derived class have significant speed improvement over the
| arraylist class?
NO!

As a CollectionBase is implemented in terms of an ArrayList.

Just be careful of using ArrayList for a collection of Points.

System.Drawing. Point is a structure, each time you add a point to your
ArrayList/CollectionBase it is going to be boxed (read performance hit) each
time you take a point out of an ArrayList/CollectionBase it is going to be
unboxed (read another performance hit).

Using List(Of T) instead of ArrayList or Collection(Of T) instead of
CollectionBase in VS 2005 will avoid this boxing & unboxing penalty.

If Profiling ArrayList/CollectionBase demonstrates that the boxing &
unboxing penalty of using Point is too great then I would consider defining
my own collection that behaves similar to ArrayList internally only it
contains an actual array of Points. Internally ArrayList is implemented as
an Array, that is over allocated. ArrayList contains the current number of
elements in this internal array. When the number of elements = the size of
the internal array, the internal array is doubled in size.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Sam" <qd*@datawave.c om> wrote in message
news:Ou******** ******@tk2msftn gp13.phx.gbl...
| 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,
|
| Sam
|
|
Nov 30 '05 #9
Sam
Hi guys

Thanks for the suggestions. I was also thinking of the cost of boxing and
unboxing penalty and it's one of my biggest concerns. So I'm gonna look into
the List(Of T) and see if speed improved

Best Regards,

Sam

"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> wrote in
message news:Ok******** ******@TK2MSFTN GP14.phx.gbl...
Sam,
| In term of processing, does
| collectionbase derived class have significant speed improvement over the
| arraylist class?
NO!

As a CollectionBase is implemented in terms of an ArrayList.

Just be careful of using ArrayList for a collection of Points.

System.Drawing. Point is a structure, each time you add a point to your
ArrayList/CollectionBase it is going to be boxed (read performance hit)
each
time you take a point out of an ArrayList/CollectionBase it is going to be
unboxed (read another performance hit).

Using List(Of T) instead of ArrayList or Collection(Of T) instead of
CollectionBase in VS 2005 will avoid this boxing & unboxing penalty.

If Profiling ArrayList/CollectionBase demonstrates that the boxing &
unboxing penalty of using Point is too great then I would consider
defining
my own collection that behaves similar to ArrayList internally only it
contains an actual array of Points. Internally ArrayList is implemented as
an Array, that is over allocated. ArrayList contains the current number of
elements in this internal array. When the number of elements = the size of
the internal array, the internal array is doubled in size.

--
Hope this helps
Jay [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Sam" <qd*@datawave.c om> wrote in message
news:Ou******** ******@tk2msftn gp13.phx.gbl...
| 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,
|
| Sam
|
|

Nov 30 '05 #10

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

Similar topics

1
21894
by: davehunt | last post by:
Hi folks, New C# programmer here. I am reading some CSV data from a file into an ArrayList. I want to get the data from the ArrayList into a 2-dimensional array. I see a few references to ..Split, but I'm not sure that's what I need. So, basically, what I have loaded into the ArrayList is:
13
11329
by: Hrvoje Voda | last post by:
How to put a specified dataset table into an array list ? Hrcko
9
1596
by: Steve | last post by:
Hello, I created a structure ABC and an array of type ABC Public Structure ABC Dim str1 As String Dim int1 As Integer End Structure Public ABC1 As New ABC, ABC2 As New ABC
4
2830
by: Peter | last post by:
I run into this situation all the time and I'm wondering what is the most efficient way to handle this issue: I'll be pulling data out of a data source and want to load the data into an array so that I can preform complicated operations against this data. The returned record count in these operations is always variable. 1. I have been using an arraylist.add function to handle non-multidemional returns but was wondering if I'm better...
5
19609
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return an Array instead of an ArrayList. Now I get the message when I try to run just my webservice...
24
4423
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what we covered was within the last week of the class and all self taught. Our prof gave us an example of a Java method used to remove elements from an array: public void searchProcess() { int outIt=0;
5
28411
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through each element but I am having issues using redim to adjust the new array. Any help or example code would be greatly appreciated. thanks!
12
14471
by: Maxwell2006 | last post by:
Hi, I declared an array like this: string scriptArgs = new string; Can I resize the array later in the code? Thank you, Max
9
5696
by: Brian Tkatch | last post by:
I'm looking for a simple way to unique an array of strings. I came up with this. Does it make sense? Am i missing anything? (Testing seems to show it to work.) Public Function Unique(ByVal List() As String) As String() ' Returns the unique values of in array, in an array. Dim Temp As New System.Collections.Specialized.StringCollection()
0
9990
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10849
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
10939
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
9655
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
7183
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6073
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4697
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4292
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3299
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.