473,379 Members | 1,170 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,379 software developers and data experts.

Arraylist vs Array vs DataTable

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
9 14589
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dan V. | last post by:
I would like to create a 2D string list (2D ArrayList ???). I would like to pass in a table or query as a parameter and have both columns transform into a 2D ArrayList. When I sort the one...
2
by: D. Shane Fowlkes | last post by:
I've been reading up on Arrays in ASP.NET. I'm going to create an two dimensional array of some type to contain 5 columns but a variable amount of rows. I read up on the ArrayList function and...
6
by: gane kol | last post by:
Hi, I have a code that creates a datatable from an arraylist, but i am getting an error in casting in for (int intRow = 0; intRow < alLCPlist.Count; intRow++) { DataRow drow =...
7
by: Peter Afonin | last post by:
Hello, I have a code that queries Active Directory and put logins and names into the ArrayList. Then I need to bind this ArrayList to the DropdDownList, making names as DataTextField and logins...
2
by: Steve | last post by:
I have a very simple datatable of 1 column which I retrieve from a database, call it 'data'. Dim data As Data.DataTable data = myobject.mymethod(parameter) I want to now turn this 'data' into...
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: sal | last post by:
Greets, I'm trying to access individual records and fields of records in an arraylist but I'm having trouble. I thinks it's a syntax problem. Why doesn't arraylist.age(1) give me '67' in the...
16
by: stojilcoviz | last post by:
I've a datagrid whose datasource is an arraylist object. The arraylist holds many instances of a specific class. I've two questions about this: 1 - Is there a way by which I can obtain a...
3
by: David | last post by:
Hi all, I am following this code... http://www.devarticles.com/c/a/C-Sharp/Interface-IEnumerable-and-IEnumerator-in-C-sharp/2/ I have come to the part with public Customers(). I am assuming...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.