arrays interesting question

Results 1 to 3 of 3

Thread: arrays interesting question

  1. #1
    Join Date
    Dec 1969

    Default arrays interesting question

    hi, everyone.<BR>just a question for those who know more about internal processes.<BR><BR>this is the code:<BR>&#060;%<BR>dim a(800)<BR>a(785) = "test"<BR>response.write a(785)<BR>%&#062;<BR><BR>the question is: is this going to work just as efficient as a similar code below:<BR><BR>&#060;%<BR>dim a(8)<BR>a(7) = "test"<BR>response.write a(7)<BR>%&#062;<BR><BR>i am just trying to think of how the array system actually works.<BR>basically what i am saying is: if i call a very large arraw but leave it all blank except for several enteries in the end, does it automatically make any space for all the enteries in between thus taking up more memory and making the whole process slower?<BR><BR>thanks in advance.<BR>Dmitri<BR>

  2. #2
    Join Date
    Dec 1969

    Default Check this out:

    &#039; Code Below<BR><BR>Dim timerStart<BR>Dim timerEnd<BR>Dim dblTotalTime<BR><BR>dblTotalTime = 0<BR><BR>timerStart = Timer<BR>Dim a(800000)<BR>a(785000) = "test"<BR>Response.Write a(785000) & "&#060;br /&#062;"<BR>timerEnd = Timer<BR><BR>dblTotalTime = timerEnd - timerStart<BR>Response.Write "Total Time: " & dblTotalTime<BR><BR>Response.Write "&#060;br /&#062;"<BR>Response.Write "&#060;br /&#062;"<BR><BR>timerStart = Timer<BR>Dim b(8)<BR>b(7) = "test"<BR>Response.Write b(7) & "&#060;br /&#062;"<BR>timerEnd = Timer<BR><BR>dblTotalTime = timerEnd - timerStart<BR>Response.Write "Total Time: " & dblTotalTime<BR><BR>Response.Write "&#060;br /&#062;"<BR>Response.Write "&#060;br /&#062;"<BR><BR><BR>&#039; -----<BR>My results look like the following (I have the dot net framework installed, so you may not be able to make such a large array):<BR>test<BR>Total Time: 2.734375E-02<BR><BR>test<BR>Total Time: 0<BR><BR>It just makes sense that it is going to take up more resources to dim a larger array. I believe that the server has to allocate the memory for the 800 (or my case 800000)variables as opposed to 8.<BR><BR>The difference is pretty negligible even in my extreme example. It is not good practice, though.

  3. #3
    Join Date
    Dec 1969

    Default See my article...

    ...on on "Variables and Values in VBScript". A 3 part series that started in March or April of 2001.<BR><BR>Yes, one of the parts discusses how arrays are laid out in memory.<BR><BR>(The short answer: 16 bytes per DIMmed element.)<BR><BR>

Posting Permissions

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