Array or ArrayList

S

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
 
C

Curtis

I would use an arraylist or possibly even a hashtable. I have only found
problems with "dynamically resizing" regular arrays.

Curtis
 
H

Herfried K. Wagner [MVP]

Sam said:
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.
 
S

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
 
H

Herfried K. Wagner [MVP]

Sam,

Sam said:
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!
 
G

Guest

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 said:
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
 
S

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
 
H

Herfried K. Wagner [MVP]

Sam,

Sam said:
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.
 
J

Jay B. Harlow [MVP - Outlook]

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


| 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
|
|
 
S

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
 
C

Cor Ligthert [MVP]

Dennis,

A point is already a structure

http://msdn.microsoft.com/library/d...ef/html/frlrfsystemdrawingpointclasstopic.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 said:
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.
 
J

Jay B. Harlow [MVP - Outlook]

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/archive/2005/09/23/Collections.aspx

http://blogs.msdn.com/kcwalina/archive/2005/09/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


| 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
|
|
|
| message | > 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
| >
| >
| > | > | 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
| > |
| > |
| >
| >
|
|
 
G

Guest

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 said:
Dennis,

A point is already a structure

http://msdn.microsoft.com/library/d...ef/html/frlrfsystemdrawingpointclasstopic.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
 
C

Cor Ligthert [MVP]

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
 
J

Jay B. Harlow [MVP - Outlook]

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/d...mCollectionsArrayListClassTrimToSizeTopic.asp

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| 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/d...ef/html/frlrfsystemdrawingpointclasstopic.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" <[email protected]> schreef in bericht
| > | > > 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
| > >>
message
| > >> | > >> >> 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/>
| > >>
| > >>
| > >>
| >
| >
| >
 
G

Guest

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 said:
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/d...mCollectionsArrayListClassTrimToSizeTopic.asp

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| 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/d...ef/html/frlrfsystemdrawingpointclasstopic.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" <[email protected]> schreef in bericht
| > | > > 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
| > >>
message
| > >> | > >> >> 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/>
| > >>
| > >>
| > >>
| >
| >
| >
 
J

Jay B. Harlow [MVP - Outlook]

| 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


| 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/d...mCollectionsArrayListClassTrimToSizeTopic.asp
| >
| > --
| > Hope this helps
| > Jay [MVP - Outlook]
| > ..NET Application Architect, Enthusiast, & Evangelist
| > T.S. Bradley - http://www.tsbradley.net
| >
| >
| > | > | 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/d...ef/html/frlrfsystemdrawingpointclasstopic.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" <[email protected]> schreef in bericht
| > | > | > | > > 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
| > | > >>
| > message
| > | > >> | > | > >> >> 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/>
| > | > >>
| > | > >>
| > | > >>
| > | >
| > | >
| > | >
| >
| >
| >
 
C

Cor Ligthert [MVP]

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
 
J

Jay B. Harlow [MVP - Outlook]

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


message || 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
|
|
| || 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/d...mCollectionsArrayListClassTrimToSizeTopic.asp
|| >
|| > --
|| > Hope this helps
|| > Jay [MVP - Outlook]
|| > ..NET Application Architect, Enthusiast, & Evangelist
|| > T.S. Bradley - http://www.tsbradley.net
|| >
|| >
|| > || > | 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/d...ef/html/frlrfsystemdrawingpointclasstopic.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" <[email protected]> schreef in bericht
|| > | > || > | > > 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
|| > | > >>
|| > message
|| > | > >> || > | > >> >> 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/>
|| > | > >>
|| > | > >>
|| > | > >>
|| > | >
|| > | >
|| > | >
|| >
|| >
|| >
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top