473,882 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14643
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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP09.phx.gbl...
Wondering the best way of storing my data.

This is data pulled and stored in the database but a lot of data
manipulatio n 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
StringCollectio n class in the System.Collecti ons.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
StringCollectio n class in the System.Collecti ons.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******** **********@TK2M SFTNGP12.phx.gb l...
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******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP09.phx.gbl...
Wondering the best way of storing my data.

This is data pulled and stored in the database but a lot of data
manipulati on 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
21481
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 'column' in the ArrayList, the other is automatically sorted and so I can use IndexOf without fear. This is because I will be going through 20,000 some odd records and don't want to use a Lookup type of table/query; I figure an ArrayList.IndexOf method...
2
2587
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 the HashTable as well. In the two books I have, there's no mention of the limitations of an ArrayList and it can only contain a single column array. But from the examples, I've seen, this seems to be true. The HashTable, as far as I can tell, can...
6
5392
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 = dtLCPack.NewRow(); int intColCount = dtLCPack.Columns.Count; ArrayList arrlRow = (ArrayList)alLCPlist; <== Specified cast
7
1408
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 as DataValueFields. I have no problem doing it, if I have only logins or only names, since ArrayList always has one dimension. But I need them both. So the code looks like this:
2
31444
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 an arraylist and I don't know how. Can anyone help?
4
2830
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 that I can preform complicated operations against this data. The returned record count in these operations is always variable. 1. I have been using an arraylist.add function to handle non-multidemional returns but was wondering if I'm better...
5
1176
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 example below what's the proper syntax? Can arraylist do this or do I have to switch to a plan array?
16
2038
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 reference to the arraylist item the current row points to? 2 - Is it possible to sort the grid? Many thanks in advance.
3
5900
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 this is a constructor (as it is the same name as the class). In here, it says Get all customer ids from the database and put into an arraylist. However, the code is for enumeration. To me, all data from a
0
9932
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9777
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11109
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10405
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5782
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4602
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.