Browse DevX
Sign up for e-mail newsletters from DevX

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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
Thanks for your registration, follow us on our social networks to keep up-to-date