我有如下的代码,总是提示提示 out of memory,求高手优化一下
Function Sparsekv(kv() As Double, ByRef KVD() As Double, ByRef kvsi() As Long, ByVal neq As Long, ByVal nband As Long) As Long
Dim i As Long, j As Long, k As Long, L As Long, n As Long, NumRows As Long, NumNon0 As Long, LB As Long, KVD2() As Double, KVsi2() As Long
Dim MaxRows As Long, IndexA() As Long
LB = LBound(kv)
NumRows = UBound(kv) - LB + 1
For i = LB To NumRows + LB - 1
If kv(i) <> 0 Then NumNon0 = NumNon0 + 1
Next i
MaxRows = neq * (nband + 1) - 1
ReDim KVD(0 To NumNon0 - 1)
ReDim kvsi(0 To NumNon0 - 1, 0 To 1)
ReDim KVD2(0 To MaxRows)
ReDim KVsi2(0 To MaxRows, 0 To 1) '在这行总是提示out of memory
ReDim IndexA(0 To neq, 0 To nband + 1) '有时候是在这行提示 提示out of memory
i = 1
n = 0
k = -1
For j = 1 To nband + 1
n = (j - 1) * (neq)
For i = 1 To neq - j + 1
If kv(n + i) <> 0 Then
k = k + 1
'L = (i - 1) * nband + k
KVD2(k) = kv(n + i)
KVsi2(k, 0) = i - 1
KVsi2(k, 1) = i + j - 2
IndexA(i - 1, 0) = IndexA(i - 1, 0) + 1
IndexA(i - 1, IndexA(i - 1, 0)) = k
End If
Next i
Next j
k = 0
For i = 0 To neq
For j = 1 To IndexA(i, 0)
n = IndexA(i, j)
KVD(k) = KVD2(n)
kvsi(k, 0) = KVsi2(n, 0)
kvsi(k, 1) = KVsi2(n, 1)
k = k + 1
Next j
Next i
End Function
我查看了一下 :
NumNon0= |
93214 |
MaxRows= |
50380469 |
neq= |
7959 |
nband= |
6329 |
.