473,324 Members | 2,370 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,324 software developers and data experts.

Saving DataTable to session vs saving a Custom object.

Hi,

I posted this in the asp.net group, but didn't get a response. Maybe someone
here can help me with this...

---

Would someone be able to shed some light on what is the cost of saving a
DataTable to session vs saving a custom object of the same data.

For example, let's say I had a DataTable with 1000 records and each record
had 10 columns, how much extra cost is involved in saving that vs, a custom
object with 10 get/set properties in a ArrayList holding 1000 instances of
the object with the same data?
Looking forward to your response.
Nov 16 '05 #1
4 10785
Short answer: It depends.

Longer answer: It depends on what type of session storage you're using.
If you're using in process sessuion, then the difference between the two
is simply the size of the object. If your using a state server or a SQL
server to maintain session information, then you need to look at how the
objects get serialized.

Just so you know, the DataTable will serialize as a diffgram, so the
size used will depend on whether the rows are freshly added (only the
new row is included) or modified (both the new and old rows are
included). ArrayLists, on the other hand serialize as little more than
the aggregated serialization of the objects that are contained.

Hope that helps.

Bruce Johnson [.NET MVP]
http://www.objectsharp.com/blogs/bruce

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #2
I don't think the session you refer to will actually result in any
serialization occurring, so the difference will just be in terms of the
memory usage. The biggest overhead you'd see in memory usage would be the
fact that you could have typed classes containing your data in an ArrayList
and you avoid the boxing overhead. DataRows, while quite optimized for
storing data, do end up boxing the data before it is stored so end up with
an extra object for each column in each row that otherwise wouldn't need to
be allocated.

--
John Wood
Blog: http://spaces.msn.com/members/johnwood/
"John Kandell" <so*****@home.now> wrote in message
news:7r*********************@news20.bellglobal.com ...
Hi,

I posted this in the asp.net group, but didn't get a response. Maybe someone here can help me with this...

---

Would someone be able to shed some light on what is the cost of saving a
DataTable to session vs saving a custom object of the same data.

For example, let's say I had a DataTable with 1000 records and each record
had 10 columns, how much extra cost is involved in saving that vs, a custom object with 10 get/set properties in a ArrayList holding 1000 instances of
the object with the same data?
Looking forward to your response.

Nov 16 '05 #3
Thanks for you reply...,

I guess what I'm really trying to figure out is what is the best pratice...,
here's the exact scenario.

The web app we are developing is a portal to a large database.
There will be approximately 1000-1500 hits per day.

The user executes a query which can return at most 1000 records (rowcount is
set to 1000). The results are displayed on a grid with pagination enabled to
100 records per page. Therefore, if the query returns 1000 records, the page
will show the grid with 100 records and links to the other 10 pages. (sorta
like your typical search engine.)

The paging is controlled by the webgrid control, not the stored proc used to
get the data. (ie the stored proc returns the complete result set.)

We are using SQL Server to store our session variables, and the app is
running on a webfarm with 4 servers.

*The requirements are to have the HTML as small as possible, and the limit
the roundtrips to the database.* Therefore, we opted to storing the results
in a session variable, so, when the user clicks on the "page 2" to see more
data, the data is read from the session, instead of being read again from
the database.

So, the question is then, is it better to use a DataTable to keep the data
in session, or use the datareader to populate an array of a custom object?
What are the cost and benefits of either approach? Is there a better
solution?
Looking forward to your response.

"Bruce Johnson" <bj******@spammenot.objectsharp.com> wrote in message
news:uA*************@TK2MSFTNGP12.phx.gbl...
Short answer: It depends.

Longer answer: It depends on what type of session storage you're using.
If you're using in process sessuion, then the difference between the two
is simply the size of the object. If your using a state server or a SQL
server to maintain session information, then you need to look at how the
objects get serialized.

Just so you know, the DataTable will serialize as a diffgram, so the
size used will depend on whether the rows are freshly added (only the
new row is included) or modified (both the new and old rows are
included). ArrayLists, on the other hand serialize as little more than
the aggregated serialization of the objects that are contained.

Hope that helps.

Bruce Johnson [.NET MVP]
http://www.objectsharp.com/blogs/bruce

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4
First off, to answer Mr. Wood, there *are* instances where an object
needs to be serialized. Specifically, that is when a state server or a
SQL Server is being used to maintain state. And that is the situation
described here.

Now on to the particulars of this situation. My first thought is
question whether storing the query results in a session are going to
result in that much of a performance gain. After all, you need to hit
SQL Server in order to retrieve the previously saved session
information. Is that really going to be that much better than rerunning
the original query? That is probably something I'd want to benchmark.

If we assume that storing the results in session is a good thing, then I
suspect that the ArrayList of custom objects will be the better choice.
My rationale is because the DataTable, like I said, serializes as a
DiffGram-style XML document. Which means that to rehydrate the
DataTable means that, basically, the ReadXml method is called using the
DiffGram type. And XML documents are relatively slow to operate with.

That having been said, it would probably be best (and relatively easy)
to benchmark the two techniques just to be sure

Bruce Johnson [.NET MVP]
http://www.objectsharp.com/blogs/bruce

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Abhilash.k.m | last post by:
This is regarding the session management using Out of proc session management(SQL SERVER). Among the samples below which one is better to set the session? 1. There are 20 session...
1
by: Mike | last post by:
I have an ASP.NET/VB app that updates values in a DataTable over the course of about 3 different pages. On the way out of the first of these pages, I explicitly build the DataTable from values in...
2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
4
by: John Kandell | last post by:
Hi, Would someone be able to shed some light on what is the cost of saving a DataTable to session vs saving a custom object of the same data. For example, let's say I had a DataTable with 1000...
3
by: Datatable Dataset Datagrid help | last post by:
Hi I am somewhat confused, I am new at VB.net I use XML data, I have a datagrid, I created a datatable so that I can create a custom format like true is this graphic false is this graphic and...
2
by: simonZ | last post by:
I have a dataTable in my memory(session). Can I save this table into sql dataTable in one step? Now, I'm iterating through the records and saving record by record with command object. But...
3
by: Phill W. | last post by:
OK, I've asked nicely before; now I'm going to throw down the gauntlet to anyone brave enough to take it up. In VB'2005, can anyone write me a class that inherits from System.Data.DataTable, add...
4
by: =?Utf-8?B?YmFzdWxhc3o=?= | last post by:
Hi; I want to store a datatable (or an arraylist) as a session variable but when I try; Session = al_RecNo; I get an error that; "Cannot implicitly convert type...
0
by: tina2626 | last post by:
I m using this code in C#.net, for dynamic creation of GridView without using DB. <CODE> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) {...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.