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

Arraylist vs Array vs DataTable

P: n/a
Wondering the best way of storing my data.

This is data pulled and stored in the database but a lot of data
manipulation goes on the client side. I never have to remove items but
will sometimes clear them all out. It seems to me the best way,
resource wise, would be just a string array and then use redim when I
have to add a new "row" of data. Arraylist & datatables seem easier to
work with, but since I don't need much of the extra's that they add, the
overhead seems too much price to pay...

Any thoughts?
Chris
Nov 21 '05 #1
Share this Question
Share on Google+
9 Replies

P: n/a
It depends a lot on the amount of data you are talking about and such. I
have excellent results with arraylists, swear by them. I also find
hashtables quite nice. From an overhead perspective - I have stored
thousands of objects in an arraylist before and it moves along quite fast.
If you need to sort, search, etc - super fun there. As for quick access to
an object, hashtables also have their great moments.

For situations where a flexible size was important, I suggest arraylist, but
if you are pulling down data from SQL Server or similar, a datatable will
provide you a lot of stuff specificly useful to the server.

HTH
Derek

"Chris" <no@spam.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl...
Wondering the best way of storing my data.

This is data pulled and stored in the database but a lot of data
manipulation goes on the client side. I never have to remove items but
will sometimes clear them all out. It seems to me the best way, resource
wise, would be just a string array and then use redim when I have to add a
new "row" of data. Arraylist & datatables seem easier to work with, but
since I don't need much of the extra's that they add, the overhead seems
too much price to pay...

Any thoughts?
Chris

Nov 21 '05 #2

P: n/a
Derek Martin wrote:
It depends a lot on the amount of data you are talking about and such. I
have excellent results with arraylists, swear by them. I also find
hashtables quite nice. From an overhead perspective - I have stored
thousands of objects in an arraylist before and it moves along quite fast.
If you need to sort, search, etc - super fun there. As for quick access to
an object, hashtables also have their great moments.

For situations where a flexible size was important, I suggest arraylist, but
if you are pulling down data from SQL Server or similar, a datatable will
provide you a lot of stuff specificly useful to the server.

HTH
Derek

"Chris" <no@spam.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl...
Wondering the best way of storing my data.

This is data pulled and stored in the database but a lot of data
manipulation goes on the client side. I never have to remove items but
will sometimes clear them all out. It seems to me the best way, resource
wise, would be just a string array and then use redim when I have to add a
new "row" of data. Arraylist & datatables seem easier to work with, but
since I don't need much of the extra's that they add, the overhead seems
too much price to pay...

Any thoughts?
Chris



Like I said, I don't need any of the sorting, searching and extras that
those object give me. Just need a place to store the data while we are
editing it. I was just kinda curious if there was much overhead there
was of using ArrayLists vs Arrays. I mean I assume that Arraylist deep
down is just an array and is just doing a redim when I do an add. So
why should I hold onto all the overhead for a simple datastore.

Thanks for your thoughts.
Chris
Nov 21 '05 #3

P: n/a
You will have to pay a price when ReDim'ing an array as that will
create a 'new' array and copy all the elements to it. If you like
working with Array semantics, then an ArrayList is a good choice. If
you know you'll be working with strings, you might take a look at the
StringCollection class in the System.Collections.Specialized namespace.

Nov 21 '05 #4

P: n/a
Chris,

Is this for a commodore 64, this kind of problems is in my opinion not for
today anymore (or is should be for a PDA).

The only problem I can think of is about deleting very much rows in one
time, because that is a crime in a datatable in VS2002/2003.

For the rest take the one which makes your program the much readable.

Data from a database; datatable
Dynamic array; arraylist
Static array; array

Just my thought,

Cor
Nov 21 '05 #5

P: n/a
Chris Dunaway wrote:
You will have to pay a price when ReDim'ing an array as that will
create a 'new' array and copy all the elements to it. If you like
working with Array semantics, then an ArrayList is a good choice. If
you know you'll be working with strings, you might take a look at the
StringCollection class in the System.Collections.Specialized namespace.


If I:

Dim Array(4) as String
.... Add Data to Array
ReDim Preserve Array(5)

All 5 of the items in Array get copied over when I redim? I didn't know
that. Do I take the same hit useing an ArrayList.Add()?

Chris
Nov 21 '05 #6

P: n/a
Cor Ligthert [MVP] wrote:
Chris,

Is this for a commodore 64, this kind of problems is in my opinion not for
today anymore (or is should be for a PDA).

The only problem I can think of is about deleting very much rows in one
time, because that is a crime in a datatable in VS2002/2003.

For the rest take the one which makes your program the much readable.

Data from a database; datatable
Dynamic array; arraylist
Static array; array

Just my thought,

Cor

"The only problem I can think of is about deleting very much rows in one
time, because that is a crime in a datatable in VS2002/2003."
Can you explain this a bit more?
"Is this for a commodore 64, this kind of problems is in my opinion not
or today anymore (or is should be for a PDA)."
I do have to be concerned about memory in this application. It is going
to be running on TS, so I don't want to eat memory and other resources
just becauses it is easier....

Chris
Nov 21 '05 #7

P: n/a
Some good advice Cor, overhead and memory consumption should always be taken
into consideration, but they aren't make or break like they once were.

Derek

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
Chris,

Is this for a commodore 64, this kind of problems is in my opinion not for
today anymore (or is should be for a PDA).

The only problem I can think of is about deleting very much rows in one
time, because that is a crime in a datatable in VS2002/2003.

For the rest take the one which makes your program the much readable.

Data from a database; datatable
Dynamic array; arraylist
Static array; array

Just my thought,

Cor

Nov 21 '05 #8

P: n/a
Like I said, it's your call there really Chris. Arraylist does derive from
array on down in the plumbing, but the overhead issue isn't so much with the
object's added properties but what you're doing with the data - if you can
use the features of Arraylist without Redimming, go for it - I hate
redimming just cause I was taught that way for whatever that's worth :-)

Derek
"Chris" <no@spam.com> wrote in message
news:eE**************@TK2MSFTNGP14.phx.gbl...
Derek Martin wrote:
It depends a lot on the amount of data you are talking about and such. I
have excellent results with arraylists, swear by them. I also find
hashtables quite nice. From an overhead perspective - I have stored
thousands of objects in an arraylist before and it moves along quite
fast. If you need to sort, search, etc - super fun there. As for quick
access to an object, hashtables also have their great moments.

For situations where a flexible size was important, I suggest arraylist,
but if you are pulling down data from SQL Server or similar, a datatable
will provide you a lot of stuff specificly useful to the server.

HTH
Derek

"Chris" <no@spam.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl...
Wondering the best way of storing my data.

This is data pulled and stored in the database but a lot of data
manipulation goes on the client side. I never have to remove items but
will sometimes clear them all out. It seems to me the best way, resource
wise, would be just a string array and then use redim when I have to add
a new "row" of data. Arraylist & datatables seem easier to work with,
but since I don't need much of the extra's that they add, the overhead
seems too much price to pay...

Any thoughts?
Chris



Like I said, I don't need any of the sorting, searching and extras that
those object give me. Just need a place to store the data while we are
editing it. I was just kinda curious if there was much overhead there was
of using ArrayLists vs Arrays. I mean I assume that Arraylist deep down
is just an array and is just doing a redim when I do an add. So why
should I hold onto all the overhead for a simple datastore.

Thanks for your thoughts.
Chris

Nov 21 '05 #9

P: n/a
You don't need to, no. The array is probably better than the array list
with < 1000 items or so, depending on how you use it. The arraylist is just
allocating more storage than you need so in the average case it doesn't need
to ReDim when adding an item.

I tend to store database objects in hashtables, keyed on the database
primary key of course. If you are wiping the entire table though and don't
care about keys, then I would suggest an arraylist. It will scale better
than a basic array and isn't any more difficult to use. The only thing is
boxing/unboxing, which might slow you down a tiny bit - but not in any
noticable way I don't think.


Like I said, I don't need any of the sorting, searching and extras that
those object give me. Just need a place to store the data while we are
editing it. I was just kinda curious if there was much overhead there was
of using ArrayLists vs Arrays. I mean I assume that Arraylist deep down
is just an array and is just doing a redim when I do an add. So why
should I hold onto all the overhead for a simple datastore.

Thanks for your thoughts.
Chris

Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.