473,397 Members | 2,077 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,397 software developers and data experts.

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 3216
I would use an arraylist or possibly even a hashtable. I have only found
problems with "dynamically resizing" regular arrays.

Curtis

"Sam" <qd*@datawave.com> wrote in message
news:Ou**************@tk2msftngp13.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.com> 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****************@tk2msftngp13.phx.gbl...
"Sam" <qd*@datawave.com> 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.com> 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
'StringCollection' 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****************@tk2msftngp13.phx.gbl...
"Sam" <qd*@datawave.com> 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**************@TK2MSFTNGP15.phx.gbl...
Sam,

"Sam" <qd*@datawave.com> 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
'StringCollection' 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.com> 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 'TreeNodeCollection' 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.com> wrote in message
news:Ou**************@tk2msftngp13.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**************@TK2MSFTNGP14.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.com> wrote in message
news:Ou**************@tk2msftngp13.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
Dennis,

A point is already a structure

http://msdn.microsoft.com/library/de...classtopic.asp

Therefore I think that I would go for the already by Herfrieds mentioned
solution "the generic list" if Sam has VS 2005.

For me it seems build for this problem.
\\\
Public Class Form1
Public ScreenPoints As New List(Of Point)
Private Sub Form1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Click
ScreenPoints.Add(New Point(Cursor.Position.X, Cursor.Position.Y))
End Sub
End Class
///

Just my idea.

Cor

"Dennis" <De****@discussions.microsoft.com> schreef in bericht
news:CD**********************************@microsof t.com...
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****************@tk2msftngp13.phx.gbl...
> "Sam" <qd*@datawave.com> 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 #11
Sam,
FWIW:

Collection(Of T) is the Generics replacement for CollectionBase, while
KeyedCollection(Of K, T) is the Generics "replacement" for DictionaryBase.

http://blogs.msdn.com/kcwalina/archi...llections.aspx

http://blogs.msdn.com/kcwalina/archi...26/474010.aspx

The above blog also lists some common 1.1 collections with their common 2.0
generic "replacements".

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Sam" <qd*@datawave.ca> wrote in message
news:OQ**************@TK2MSFTNGP11.phx.gbl...
| 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**************@TK2MSFTNGP14.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.com> wrote in message
| > news:Ou**************@tk2msftngp13.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 #12
My point was that one could use any type structure or class for that matter.
Also, I don't understand why people are hung up on using ArrayLists so much.
Granted, they are better in cases where you have no idea of the maximum but
they also redim preserve every time the count gets to the maximum size
although they double the size every time or am I wrong. If I'm correct, then
one disadvantage of array lists in Sam's case is that you could easily end up
with 50,000 or 60,000 size of an arraylist when you only needed a maximum of
30,000 unless you set the starting size of the arraylist at 30,000. In this
case, an array would be, I think, faster and easier.
--
Dennis in Houston
"Cor Ligthert [MVP]" wrote:
Dennis,

A point is already a structure

http://msdn.microsoft.com/library/de...classtopic.asp

Therefore I think that I would go for the already by Herfrieds mentioned
solution "the generic list" if Sam has VS 2005.

For me it seems build for this problem.
\\\
Public Class Form1
Public ScreenPoints As New List(Of Point)
Private Sub Form1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Click
ScreenPoints.Add(New Point(Cursor.Position.X, Cursor.Position.Y))
End Sub
End Class
///

Just my idea.

Cor

"Dennis" <De****@discussions.microsoft.com> schreef in bericht
news:CD**********************************@microsof t.com...
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****************@tk2msftngp13.phx.gbl...
> "Sam" <qd*@datawave.com> 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/>


Dec 1 '05 #13
Dennis,

I did agree with the idea behind your message.

I was even thinking about a byteArea. However, than I thought what is 100Kb
in a current computer.

Cor
Dec 1 '05 #14
Dennis,
| with 50,000 or 60,000 size of an arraylist when you only needed a maximum
of
| 30,000 unless you set the starting size of the arraylist at 30,000.
Yes that is a factor...

If you are going to keep the ArrayList object for a while, you can use
ArrayList.TrimToSize to discard the unused elements:

http://msdn.microsoft.com/library/de...oSizeTopic.asp

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:07**********************************@microsof t.com...
| My point was that one could use any type structure or class for that
matter.
| Also, I don't understand why people are hung up on using ArrayLists so
much.
| Granted, they are better in cases where you have no idea of the maximum
but
| they also redim preserve every time the count gets to the maximum size
| although they double the size every time or am I wrong. If I'm correct,
then
| one disadvantage of array lists in Sam's case is that you could easily end
up
| with 50,000 or 60,000 size of an arraylist when you only needed a maximum
of
| 30,000 unless you set the starting size of the arraylist at 30,000. In
this
| case, an array would be, I think, faster and easier.
| --
| Dennis in Houston
|
|
| "Cor Ligthert [MVP]" wrote:
|
| > Dennis,
| >
| > A point is already a structure
| >
| >
http://msdn.microsoft.com/library/de...classtopic.asp
| >
| > Therefore I think that I would go for the already by Herfrieds mentioned
| > solution "the generic list" if Sam has VS 2005.
| >
| > For me it seems build for this problem.
| > \\\
| > Public Class Form1
| > Public ScreenPoints As New List(Of Point)
| > Private Sub Form1_Click(ByVal sender As Object, _
| > ByVal e As System.EventArgs) Handles Me.Click
| > ScreenPoints.Add(New Point(Cursor.Position.X,
Cursor.Position.Y))
| > End Sub
| > End Class
| > ///
| >
| > Just my idea.
| >
| > Cor
| >
| > "Dennis" <De****@discussions.microsoft.com> schreef in bericht
| > news:CD**********************************@microsof t.com...
| > > 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****************@tk2msftngp13.phx.gbl...
| > >> > "Sam" <qd*@datawave.com> 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/>
| > >>
| > >>
| > >>
| >
| >
| >
Dec 1 '05 #15
Yes but not before you are thru adding. Doesn't an arraylist double in size
everytime it's count exceeds it's maximum size. If you are at 25,000 count
and the array was at it's maximum, it would resize to 50k. To avoid this, you
could an arraylist size at your maximum of 30,000 then trim it when you are
done but what's then in is the advantage in this case of the arraylist over
an array sized to 30k then redim preserved at the end?
--
Dennis in Houston
"Jay B. Harlow [MVP - Outlook]" wrote:
Dennis,
| with 50,000 or 60,000 size of an arraylist when you only needed a maximum
of
| 30,000 unless you set the starting size of the arraylist at 30,000.
Yes that is a factor...

If you are going to keep the ArrayList object for a while, you can use
ArrayList.TrimToSize to discard the unused elements:

http://msdn.microsoft.com/library/de...oSizeTopic.asp

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:07**********************************@microsof t.com...
| My point was that one could use any type structure or class for that
matter.
| Also, I don't understand why people are hung up on using ArrayLists so
much.
| Granted, they are better in cases where you have no idea of the maximum
but
| they also redim preserve every time the count gets to the maximum size
| although they double the size every time or am I wrong. If I'm correct,
then
| one disadvantage of array lists in Sam's case is that you could easily end
up
| with 50,000 or 60,000 size of an arraylist when you only needed a maximum
of
| 30,000 unless you set the starting size of the arraylist at 30,000. In
this
| case, an array would be, I think, faster and easier.
| --
| Dennis in Houston
|
|
| "Cor Ligthert [MVP]" wrote:
|
| > Dennis,
| >
| > A point is already a structure
| >
| >
http://msdn.microsoft.com/library/de...classtopic.asp
| >
| > Therefore I think that I would go for the already by Herfrieds mentioned
| > solution "the generic list" if Sam has VS 2005.
| >
| > For me it seems build for this problem.
| > \\\
| > Public Class Form1
| > Public ScreenPoints As New List(Of Point)
| > Private Sub Form1_Click(ByVal sender As Object, _
| > ByVal e As System.EventArgs) Handles Me.Click
| > ScreenPoints.Add(New Point(Cursor.Position.X,
Cursor.Position.Y))
| > End Sub
| > End Class
| > ///
| >
| > Just my idea.
| >
| > Cor
| >
| > "Dennis" <De****@discussions.microsoft.com> schreef in bericht
| > news:CD**********************************@microsof t.com...
| > > 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****************@tk2msftngp13.phx.gbl...
| > >> > "Sam" <qd*@datawave.com> 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/>
| > >>
| > >>
| > >>
| >
| >
| >

Dec 2 '05 #16
| done but what's then in is the advantage in this case of the arraylist
over
| an array sized to 30k then redim preserved at the end?

I would say primarily ArrayList like the rest of the Framework has already
been written & more importantly tested, saving you the time of writing &
testing your own version of the routine.

Seeing as ArrayList is already written, you can spend your time solving your
actual business probably, rather then creating general classes such as
ArrayList...

Of course writing your own ArrayList style class allows you to customize the
allocation algorithm, possibly with a replaceable one via the Strategy
pattern.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
| Yes but not before you are thru adding. Doesn't an arraylist double in
size
| everytime it's count exceeds it's maximum size. If you are at 25,000 count
| and the array was at it's maximum, it would resize to 50k. To avoid this,
you
| could an arraylist size at your maximum of 30,000 then trim it when you
are
| done but what's then in is the advantage in this case of the arraylist
over
| an array sized to 30k then redim preserved at the end?
| --
| Dennis in Houston
|
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Dennis,
| > | with 50,000 or 60,000 size of an arraylist when you only needed a
maximum
| > of
| > | 30,000 unless you set the starting size of the arraylist at 30,000.
| > Yes that is a factor...
| >
| > If you are going to keep the ArrayList object for a while, you can use
| > ArrayList.TrimToSize to discard the unused elements:
| >
| >
http://msdn.microsoft.com/library/de...oSizeTopic.asp
| >
| > --
| > Hope this helps
| > Jay [MVP - Outlook]
| > ..NET Application Architect, Enthusiast, & Evangelist
| > T.S. Bradley - http://www.tsbradley.net
| >
| >
| > "Dennis" <De****@discussions.microsoft.com> wrote in message
| > news:07**********************************@microsof t.com...
| > | My point was that one could use any type structure or class for that
| > matter.
| > | Also, I don't understand why people are hung up on using ArrayLists so
| > much.
| > | Granted, they are better in cases where you have no idea of the
maximum
| > but
| > | they also redim preserve every time the count gets to the maximum size
| > | although they double the size every time or am I wrong. If I'm
correct,
| > then
| > | one disadvantage of array lists in Sam's case is that you could easily
end
| > up
| > | with 50,000 or 60,000 size of an arraylist when you only needed a
maximum
| > of
| > | 30,000 unless you set the starting size of the arraylist at 30,000.
In
| > this
| > | case, an array would be, I think, faster and easier.
| > | --
| > | Dennis in Houston
| > |
| > |
| > | "Cor Ligthert [MVP]" wrote:
| > |
| > | > Dennis,
| > | >
| > | > A point is already a structure
| > | >
| > | >
| >
http://msdn.microsoft.com/library/de...classtopic.asp
| > | >
| > | > Therefore I think that I would go for the already by Herfrieds
mentioned
| > | > solution "the generic list" if Sam has VS 2005.
| > | >
| > | > For me it seems build for this problem.
| > | > \\\
| > | > Public Class Form1
| > | > Public ScreenPoints As New List(Of Point)
| > | > Private Sub Form1_Click(ByVal sender As Object, _
| > | > ByVal e As System.EventArgs) Handles Me.Click
| > | > ScreenPoints.Add(New Point(Cursor.Position.X,
| > Cursor.Position.Y))
| > | > End Sub
| > | > End Class
| > | > ///
| > | >
| > | > Just my idea.
| > | >
| > | > Cor
| > | >
| > | > "Dennis" <De****@discussions.microsoft.com> schreef in bericht
| > | > news:CD**********************************@microsof t.com...
| > | > > 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****************@tk2msftngp13.phx.gbl...
| > | > >> > "Sam" <qd*@datawave.com> 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/>
| > | > >>
| > | > >>
| > | > >>
| > | >
| > | >
| > | >
| >
| >
| >
Dec 2 '05 #17
Dennis,

I think that a byte array is quicker if it will be used inside the program
to rearrange points in an intensive way. There has not any memory more to
declare.

However here it is mainly meant to save the user clicks.
Therefore the time will probably less important in this case.

Therefore I stay with a generic list of points.

Just my opinion,

Cor
Dec 2 '05 #18
Doh!

| actual business probably, rather then creating general classes such as

Thats "actual business problem"... Darn spell checker... ;-)
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
message news:er**************@TK2MSFTNGP15.phx.gbl...
|| done but what's then in is the advantage in this case of the arraylist
| over
|| an array sized to 30k then redim preserved at the end?
|
| I would say primarily ArrayList like the rest of the Framework has already
| been written & more importantly tested, saving you the time of writing &
| testing your own version of the routine.
|
| Seeing as ArrayList is already written, you can spend your time solving
your
| actual business probably, rather then creating general classes such as
| ArrayList...
|
| Of course writing your own ArrayList style class allows you to customize
the
| allocation algorithm, possibly with a replaceable one via the Strategy
| pattern.
|
| --
| Hope this helps
| Jay [MVP - Outlook]
| .NET Application Architect, Enthusiast, & Evangelist
| T.S. Bradley - http://www.tsbradley.net
|
|
| "Dennis" <De****@discussions.microsoft.com> wrote in message
| news:D1**********************************@microsof t.com...
|| Yes but not before you are thru adding. Doesn't an arraylist double in
| size
|| everytime it's count exceeds it's maximum size. If you are at 25,000
count
|| and the array was at it's maximum, it would resize to 50k. To avoid this,
| you
|| could an arraylist size at your maximum of 30,000 then trim it when you
| are
|| done but what's then in is the advantage in this case of the arraylist
| over
|| an array sized to 30k then redim preserved at the end?
|| --
|| Dennis in Houston
||
||
|| "Jay B. Harlow [MVP - Outlook]" wrote:
||
|| > Dennis,
|| > | with 50,000 or 60,000 size of an arraylist when you only needed a
| maximum
|| > of
|| > | 30,000 unless you set the starting size of the arraylist at 30,000.
|| > Yes that is a factor...
|| >
|| > If you are going to keep the ArrayList object for a while, you can use
|| > ArrayList.TrimToSize to discard the unused elements:
|| >
|| >
|
http://msdn.microsoft.com/library/de...oSizeTopic.asp
|| >
|| > --
|| > Hope this helps
|| > Jay [MVP - Outlook]
|| > ..NET Application Architect, Enthusiast, & Evangelist
|| > T.S. Bradley - http://www.tsbradley.net
|| >
|| >
|| > "Dennis" <De****@discussions.microsoft.com> wrote in message
|| > news:07**********************************@microsof t.com...
|| > | My point was that one could use any type structure or class for that
|| > matter.
|| > | Also, I don't understand why people are hung up on using ArrayLists
so
|| > much.
|| > | Granted, they are better in cases where you have no idea of the
| maximum
|| > but
|| > | they also redim preserve every time the count gets to the maximum
size
|| > | although they double the size every time or am I wrong. If I'm
| correct,
|| > then
|| > | one disadvantage of array lists in Sam's case is that you could
easily
| end
|| > up
|| > | with 50,000 or 60,000 size of an arraylist when you only needed a
| maximum
|| > of
|| > | 30,000 unless you set the starting size of the arraylist at 30,000.
| In
|| > this
|| > | case, an array would be, I think, faster and easier.
|| > | --
|| > | Dennis in Houston
|| > |
|| > |
|| > | "Cor Ligthert [MVP]" wrote:
|| > |
|| > | > Dennis,
|| > | >
|| > | > A point is already a structure
|| > | >
|| > | >
|| >
|
http://msdn.microsoft.com/library/de...classtopic.asp
|| > | >
|| > | > Therefore I think that I would go for the already by Herfrieds
| mentioned
|| > | > solution "the generic list" if Sam has VS 2005.
|| > | >
|| > | > For me it seems build for this problem.
|| > | > \\\
|| > | > Public Class Form1
|| > | > Public ScreenPoints As New List(Of Point)
|| > | > Private Sub Form1_Click(ByVal sender As Object, _
|| > | > ByVal e As System.EventArgs) Handles Me.Click
|| > | > ScreenPoints.Add(New Point(Cursor.Position.X,
|| > Cursor.Position.Y))
|| > | > End Sub
|| > | > End Class
|| > | > ///
|| > | >
|| > | > Just my idea.
|| > | >
|| > | > Cor
|| > | >
|| > | > "Dennis" <De****@discussions.microsoft.com> schreef in bericht
|| > | > news:CD**********************************@microsof t.com...
|| > | > > 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****************@tk2msftngp13.phx.gbl...
|| > | > >> > "Sam" <qd*@datawave.com> 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/>
|| > | > >>
|| > | > >>
|| > | > >>
|| > | >
|| > | >
|| > | >
|| >
|| >
|| >
|
|
Dec 2 '05 #19

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

Similar topics

1
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...
13
by: Hrvoje Voda | last post by:
How to put a specified dataset table into an array list ? Hrcko
9
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
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...
5
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...
24
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...
5
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...
12
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
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...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.