【编程技术】求高手看看如下的VBA代码,目前总是error,说 out of memory
所在版块:技术の宅 发贴时间:2015-05-12 19:06

用户信息
复制本帖HTML代码
高亮: 今天贴 X 昨天贴 X 前天贴 X 

我有如下的代码,总是提示提示 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
.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!

 相关帖子 我要回复↙ ↗回到正文
【编程技术】求高手看看如下的VBA代码,目前总是error,说 out of memory mydreamsg   (3325 bytes , 475reads )
,谢谢你的建议 mydreamsg   (0 bytes , 93reads )
楼主不如谈谈想实现什么... 说不定可以少用些 FOR 功夫熊猫   (0 bytes , 77reads )
有什么解决办法没有啊? mydreamsg   (0 bytes , 86reads )
试试定义两个array:kvsi20和kvsi21. 不要二维数组kvsi2. 换一个memory大的机器。 赶超美日   (0 bytes , 73reads )
二维数组太大了,50Mx 2x8=800M Byte 赶超美日   (0 bytes , 77reads )