View Full Version : Session Variables vs. Local Variables
Daniel Hui
10-12-1999, 10:05 AM
If I use a session variable several times on one ASP page, would it be more efficient to assign that session variable to a local variable at the top of the page and interact with the data via that local variable?<BR><BR>i.e. do session variables require more cycles than local variables?
Scott Mitchell
10-13-1999, 11:03 AM
I don't know for sure, but I would assume that you would want to store it in a local variable. I know with other objects, if you plan on using an object variable multiple times, it makes sense to store it into a local variable. I assume the same for Session variables, but have no proof to back it up.
AndrewConnell
10-16-1999, 08:54 AM
I've read in many places that using session, application, and cookie variables repeatedly on a single page is significantly slower than saving them to a local variable and then referencing the local variables.
Mark Vick
10-18-1999, 01:26 PM
This is a definate yes - not sure on how many times you would need to access the local variable to compensate for the assignment from Session to Local, but I have seen (very recently) documentation on this from Microsoft in a whitepaper discussing performance.<BR>In general, if I am going to use a Session variable more than twice on a page, I transfer it to local first.<BR>But, I am also trying to just plain TYPE less . . . :)<BR>
X-MAN
10-29-1999, 05:53 PM
Most languages that allow Global(session)/Local Varibles perform better when that Global variable is placed in a Local one for processing... Plus it can help make the code easier to read when you come back to it after a period of time... Unless you have a need to pass variables hidden from the user from page to page use local variables and the Request/Response objects to do what you need...
Vikram Koneri
11-13-1999, 05:30 AM
I believe the same is true of using Request object. I typically transfer them to local variables if they will be used multiple times in the page. Just a strong feel since accessing an objects methods and properties though organised would definitely costly when using repeatedly.<BR>Tell me if I am wrong on these assumptions.
vBulletin® v3.7.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.