代码之家  ›  专栏  ›  技术社区  ›  Brian

使用VB6查询加快目录漫游:缓存和Ram问题?

  •  1
  • Brian  · 技术社区  · 17 年前

    Private Function countFiles(Name As String) As Long
        On Error GoTo ErrorHandler
        DoEvents
        Const CurMthd = "countFiles"
              Dim retval As Long
    13        Dim FindData As win.WIN32_FIND_DATA
    14        Dim SearchPath As String
    15        Dim FileName As String
    17        Dim SearchHandle As Long
              If Right(Name, 1) <> "\" Then Name = Name & "\"
    19        SearchPath = Name & "*.*"
    20        SearchHandle = win.FindFirstFile(SearchPath, FindData)
              Do
                  DoEvents
    '             g_Cancel = True
                  If g_Cancel Then
                    countFiles = retval
                    Exit Function
                End If
    22            If SearchHandle = win.INVALID_HANDLE_VALUE Or SearchHandle =     ERROR_NO_MORE_FILES Then Exit Do
    23            FileName = dsMain.RetainedStrFromPtrA(VarPtr(FindData.cFileName(0)))
    24            If AscW(FileName) <> 46 Then
                        If (FindData.dwFileAttributes And win.FILE_ATTRIBUTE_DIRECTORY)     Then
                            retval = retval + countFiles(Name & FileName)
                        Else
                            retval = retval + 1
                        End If
    28            End If
    29        Loop Until win.FindNextFile(SearchHandle, FindData) = 0
        win.FindClose SearchHandle
        countFiles = retval
        Exit Function
    ErrorHandler:
        Debug.Print "Oops: " & Erl & ":" & Err.Description
        Resume Next
    End Function
    
    1 回复  |  直到 11 年前
        1
  •  1
  •   davr    17 年前

    操作系统本身缓存从磁盘读取的数据。这完全超出了你的计划,你真的无法控制它。因此,当您运行“ram clearing”程序时,它会清除这些缓存。这就是为什么那些“ram清除”程序通常是完全无用的-正如你所看到的,清空缓存会使你的程序运行得更慢。