登录 | 首页 -> 华新鲜事 -> 技术の宅 | 切换到:传统版 / sForum | 树形列表
【编程技术】求高手看看如下的VBA代码,目前总是error,说 out of memory
<<始页  [1]  末页>> 

【编程技术】求高手看看如下的VBA代码,目前总是error,说 out of memory我有如下的代码,总是提示提示 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
[mydreamsg (5-12 19:06, Long long ago)] [ 传统版 | sForum ][登录后回复]1楼

二维数组太大了,50Mx 2x8=800M Byte  [本文发送自华新手机Wap版] [赶超美日 (5-12 19:20, Long long ago)] [ 传统版 | sForum ][登录后回复]2楼

有什么解决办法没有啊?[mydreamsg (5-12 19:29, Long long ago)] [ 传统版 | sForum ][登录后回复]3楼

(引用 mydreamsg:有什么解决办法没有啊?)试试定义两个array:kvsi20和kvsi21. 不要二维数组kvsi2. 换一个memory大的机器。  [本文发送自华新手机Wap版] [赶超美日 (5-12 19:47, Long long ago)] [ 传统版 | sForum ][登录后回复]4楼

楼主不如谈谈想实现什么... 说不定可以少用些 FOR[功夫熊猫 (5-12 19:57, Long long ago)] [ 传统版 | sForum ][登录后回复]5楼

,谢谢你的建议[mydreamsg (5-12 20:04, Long long ago)] [ 传统版 | sForum ][登录后回复]6楼


<<始页  [1]  末页>> 
登录 | 首页 -> 华新鲜事 -> 技术の宅 | [刷新本页] | 切换到:传统版 / sForum