Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

was wondering if there would be any difference between literal values and datatable placed in a session, suppose i have these

 

       Session("object1") = "the string"
       Session("object2") = 100
       Session("object3") = True

 

and these

 

       Dim dt As New DataTable("objects")
       Dim dr As DataRow

       dr = dt.NewRow
       With dr
           .Item("object1") = "the string"
           .Item("object2") = 100
           .Item("object3") = True
       End With
       dt.Rows.Add(dr)

       Session("objects") = dt

 

would it differ in performance? (probably will) what could be the best practice? (in general), just curious

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Posted
was wondering if there would be any difference between literal values and datatable placed in a session, suppose i have these

 

       Session("object1") = "the string"
       Session("object2") = 100
       Session("object3") = True

 

and these

 

       Dim dt As New DataTable("objects")
       Dim dr As DataRow

       dr = dt.NewRow
       With dr
           .Item("object1") = "the string"
           .Item("object2") = 100
           .Item("object3") = True
       End With
       dt.Rows.Add(dr)

       Session("objects") = dt

 

would it differ in performance? (probably will) what could be the best practice? (in general), just curious

 

The less objects in the Session state - the better and faster.

Posted
The less objects in the Session state - the better and faster.

 

so using datatable is a little slower?

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Posted
so using datatable is a little slower?

 

Yes, and here is the good explanation why:

 

ASP.NET performs the serialization/deserialization of certain "basic" types using an optimized internal method. ("Basic" types include numeric types of all sizes (e.g. Int, Byte, Decimal, String, DateTime, TimeSpan, Guid, IntPtr and UIntPtr, etc)

If you have a session variable (e.g. an ArrayList object) that is not one of the "basic" types, ASP.NET will serialize/deserialize it using the BinaryFormatter, which is relatively slower.

So for performance sake it is better to store all session state data using one of the "basic" types listed above. For example, if you want to store two things, Name and Address, in session state, you can either (a) store them using two String session variables, or (b) create a class with two String members, and store that class object in a session variable. Performance wise, you should go with option (a).

Posted
thanks Igor, i guess ill set aside the lazyness and code each variable. ;)

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...