devxlogo

Caution when reading arrays stored in Application and Session variable

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 elementResponse.Write Application("mydata")(0)' read the second elementResponse.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 variablearr = Application("mydata")' read the elementsResponse.Write arr(0)Response.Write arr(1)' etc.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist