Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XmlDataDocument vs. ArrayList

Status
Not open for further replies.

Craftor

Programmer
Feb 1, 2001
420
NZ
Hi all

I need to return several collections in my code and do various processing with them once they have been returned. In terms of speed - what would be faster - creating and adding them into an XmlDataDocument and traversing the document or adding them into an Array list and looping through the items there?

Thanks as always

Craftor
:cool:
 
Array list doesn't carry the overhead of parsing the document, so it's generally faster.

My usual rule of thumb is to only use XML if the data is going to be used by the presentation layer for the user to see. If I'm just processing data internal to my application, I'll whatever other means is appropriate to the situation.

For example, one of our developers (no longer with the company) was completely enamored of XML. In several situations, he ran a query to select data, converted the data to XML, and then send the XML document back to a stored procedure that saves XML data to the database. It was processing lots of data and was incredibly slow. When we modified the code to do all of the processing in the database without the XML conversion, it ran a couple orders of magnitude faster.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
As an added note here : when working with arraylists you should avoid making it a return type if possible.

For example:

public void DisplayNames()
{
ArrayList list = myApp.GetNamesFromDB();

foreach (NameBean name in list)
{
textbox1.Text += name.First + " " + name.Last + Environment.NewLine;
}
}

The next person who calls myApp.GetNamesFromDB() won't know what type of object is inside so call .ToArray and return the bean type.

public NameBean[] GetNamesFromDB()
{
//fill your arraylist

return (NameBean) nameslist.ToArray(typeof(NameBean));
}

This is useful if you have chosen to work with ArrayLists rather than arrays or some other data object. The conversion will cause a bit of a performance hit but makes your code a lot more manageable.
 
In VS 2005, I use the new strongly typed lists instead of ArrayLists. This way there's no confusion about what's in the list that's being returned.

For example List<string> is a list containing only strings and List<BOERptInfo> contains a list of objects of the class BOERptInfo.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
Thank you all for your responses - will definitely be going with ArrayLists instead of XML.


Craftor
:cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top