lamy Posted January 22, 2006 Posted January 22, 2006 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 Quote 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
Mister E Posted January 22, 2006 Posted January 22, 2006 Both collections just store objects. So the performance is probably identical. Quote
Igor Sukhov Posted January 23, 2006 Posted January 23, 2006 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. Quote
lamy Posted January 24, 2006 Author Posted January 24, 2006 The less objects in the Session state - the better and faster. so using datatable is a little slower? Quote 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
Igor Sukhov Posted January 24, 2006 Posted January 24, 2006 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). Quote
lamy Posted January 24, 2006 Author Posted January 24, 2006 thanks Igor, i guess ill set aside the lazyness and code each variable. ;) Quote 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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.