Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VBS,IIS4,IIS5
Expertise: Intermediate
Jan 1, 2003

Caution when reading arrays stored in Application and Session variable

One of the most effective optimization techniques consists of caching data inside Application or Session variables. However, you should pay attention to how you reference to the elements in those arrays from an ASP page. In fact, the syntax of VBScript (and JavaScript as well) lets you reference elements in those arrays as follows:

' read the first element
Response.Write Application("mydata")(0)
' read the second element
Response.Write Application("mydata")(1)
' etc.
Alas, when you do so VBScript makes a copy of the entire array and then extracts the requested element, and then discard the temporary copy. If the array is large, this causes a sensible overhead, in terms of memory allocation and deallocation. You can avoid these unnecessary operations using an explicit local variable:

Dim arr
' read the array in a local variable
arr = Application("mydata")
' read the elements
Response.Write arr(0)
Response.Write arr(1)
' etc.

Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap