In Classic ASP (VBScript), if I try to create a large 2-dimensinal array, I get an "Out of Memory" error. For example, this
DIM xxx : xxx = 10000
DIM yyy : yyy = 10000
REDIM aaa(xxx, yyy)
Response.End
yeilds this
Microsoft VBScript runtime error '800a0007'
Out of memory
Is their another data structure I can use that will work, or some other workaround?
(2010-01-27) UPDATE: Upon further investigation of this legacy code I'm worki开发者_StackOverflow社区ng on, the array is sparse. In other words, only a portion of the array place holders are needed. Like this:
aaa(0, 0) = 1.23
aaa(101,12) = 1.57
aaa(3020,1200) = 2.58
etc.
I thought about changing things to store the values like this:
aaa(count) = "xxx,yyy,val"
and then using Split() to get val given x and y, but that requires a time-consuming loop through the array each time I know x and y. Is there a better solution?
You're trying to redimension the array to 10000 x 10000, which is 100,000,000 elements.
This is an array of Variants, which requires a single, contiguous 1.525 GB chunk of space, just to hold that array. If you're doing other work in the application, and running in 32bit, you're going to be limited to 2GB total for your process space. Trying to get a chunk that large is problematic.
In general, I would avoid trying to do allocations this large in a web-based application. This should be saved in the database, and the data paged out as necessary. If you need to do processing on the data, do it in a separate service, not in ASP.
If you have a sparse array, use a nested Scripting.Dictionary
to store it. This is probably the easiest and most efficient way in VBScript (barring a COM library for sparse arrays).
Set arr = CreateObject("Scripting.Dictionary")
' Adding a column: '
Dim NewCol
NewCol = CreateObject("Scripting.Dictionary")
arr.Add row, NewCol
' Adding a value in an (existing!) row/column: '
If arr.Exists(row) Then _
arr(row).Add column, value
' Retrieving a value: '
? arr(row)(column)
精彩评论