Session Variables vs. Local Variables

Results 1 to 6 of 6

Thread: Session Variables vs. Local Variables

  1. #1
    Daniel Hui Guest

    Default Session Variables vs. Local Variables

    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?

  2. #2
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: Session Variables vs. Local Variables

    I don&#039t 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.

  3. #3
    AndrewConnell Guest

    Default RE: Session Variables vs. Local Variables

    I&#039ve 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.

  4. #4
    Mark Vick Guest

    Default RE: Session Variables vs. Local Variables

    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>


  5. #5
    Join Date
    Dec 1969
    Posts
    5

    Default RE: Session Variables vs. Local Variables

    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...

  6. #6
    Vikram Koneri Guest

    Default RE: Session Variables vs. Local Variables

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •