By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,874 Members | 1,571 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,874 IT Pros & Developers. It's quick & easy.

Array or ArrayList

P: n/a
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
Share this Question
Share on Google+
18 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
| 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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.