gpt4 book ai didi

memory - 在 VB6 应用程序中识别内存占用的工具

转载 作者:IT王子 更新时间:2023-10-28 23:31:47 28 4
gpt4 key购买 nike

有哪些工具可用于将 VB6 应用程序中的内存消耗归因于它的多个组件?我可以通过查看各种计数器(私有(private)字节、工作集等)来获取整个应用程序消耗的内存,例如,在 Process Explorer 中。我想更深入地了解运行时创建的各种组件或对象消耗了多少内存。例如,计算在运行时缓存数据的大型集合消耗了多少内存,以及它如何根据集合中元素的数量而变化。

最佳答案

我最喜欢的工具必须是 DevPartner,虽然它的价格为 1,500 英镑,但并不便宜。虽然它比内存泄漏检查要多得多,但如果这就是你所需要的,你可能是地毯式轰炸 Ant 。

如果您想查看您的应用是否正确释放资源,请使用我编写的此函数将内存转储到给定位置。我将首先缓存每个变量的地址,然后在关闭时调用 DumpVariableMemory 传递对这些位置的引用,以查看它们是否已被释放。

如果您还没有,您还需要添加一个声明 fopr CopyMemory :)

    Public Function DumpVariableMemory(ByVal lngVariablePointer&, _
ByVal lngBufferSizeInBytes&) As String
'' * Object Name: DumpVariableMemory
'' * Type: Function
'' * Purpose: Returns a memory dump of the variable or pointer location
'' * Created: 21/08/2006 - 17:41:32
'' * Coder: Richard Pashley - NUPUK00008148
'' * Build Machine: W-XPRP-77
'' * Encapsulation: Full
'' * Parameters: lngVariablePointer - Long - Pointer to the data to dump
'' * lngBufferSizeInBytes - Long - Size of the dump to ouput in bytes
'' * Returns: - - String - Memory dump output as a string
'' * This will dump the memory location starting at the pointer address and
'' * ending at the address plus the offset (lngBufferSizeInBytes).
'' * You can use LenB to determine the size of the variable for the
'' * lngBufferSizeInBytes parameter if required.
'' * Example: DebugPrint DumpVariableMemory(VarPtr(lngMyLongValue),LenB(lngMyLongValue)
'' * Modified By: [Name]
'' * Date: [Date]
'' * Reason: [NUPUKxxxxxxxxx]
'' Declare locals
Dim lngBufferIterator& '' Buffer iterator
Dim lngBufferInnerIterator& '' Buffer loop inner iterator
Dim bytHexDumpArray() As Byte '' Received output buffer
Dim strDumpBuffer$ '' Formatted hex dump construction buffer
Dim lngValidatedBufferSize& '' Validated passed buffer size
'' Turn on error handling
On Error GoTo DumpVariableMemory_Err
'' Resize output buffer
ReDim bytHexDumpArray(0 To lngBufferSizeInBytes - 1) As Byte
'' Retrieve memory contents from supplied pointer
Call CopyMemory(bytHexDumpArray(0), _
ByVal lngVariablePointer, _
lngBufferSizeInBytes)
'' Format dump header
strDumpBuffer = String(81, "=") & vbCrLf & _
"Pointer Address = &h" & Hex$(lngVariablePointer) & _
" Ouput Buffer Size = " & FormatBytes(lngBufferSizeInBytes)
'' Add header seperator
strDumpBuffer = strDumpBuffer & _
vbCrLf & String(81, Chr$(61))
'' Validate buffer dimensions
If lngBufferSizeInBytes Mod 16 = 0 Then
'' Validated ok so assign
lngValidatedBufferSize = lngBufferSizeInBytes
Else
'' Refactor to base 16
lngValidatedBufferSize = _
((lngBufferSizeInBytes \ 16) + 1) * 16
End If
'' Iterate through buffer contents
For lngBufferIterator = 0 To (lngValidatedBufferSize - 1)
'' Determine if first row
If (lngBufferIterator Mod 16) = 0 Then
'' Format dump output row
strDumpBuffer = strDumpBuffer & vbCrLf & Right$(String(8, Chr$(48)) _
& Hex$(lngVariablePointer + lngBufferIterator), 8) & Space(2) & _
Right$(String(4, Chr$(48)) & Hex$(lngBufferIterator), 4) & Space(2)
End If
'' Determine required dump buffer padding
If lngBufferIterator < lngBufferSizeInBytes Then
'' Pad dump buffer
strDumpBuffer = strDumpBuffer & Right$(Chr$(48) & _
Hex(bytHexDumpArray(lngBufferIterator)), 2)
Else
'' Pad dump buffer
strDumpBuffer = strDumpBuffer & Space(2)
End If
'' Determine required dump buffer padding
If (lngBufferIterator Mod 16) = 15 Then
'' Pad dump buffer
strDumpBuffer = strDumpBuffer & Space(2)
'' Iterate through buffer row
For lngBufferInnerIterator = (lngBufferIterator - 15) To lngBufferIterator
'' Validate row width
If lngBufferInnerIterator < lngBufferSizeInBytes Then
'' Validate buffer constraints
If bytHexDumpArray(lngBufferInnerIterator) >= 32 And _
bytHexDumpArray(lngBufferInnerIterator) <= 126 Then
'' Ouput data to dump buffer row
strDumpBuffer = strDumpBuffer & _
Chr$(bytHexDumpArray(lngBufferInnerIterator))
Else
'' Pad dump buffer
strDumpBuffer = strDumpBuffer & Chr$(45)
End If
End If
Next
'' Determine required dump buffer padding
ElseIf (lngBufferIterator Mod 8) = 7 Then
'' Pad dump buffer
strDumpBuffer = strDumpBuffer & Chr$(45)
Else
'' Pad dump buffer
strDumpBuffer = strDumpBuffer & Space(1)
End If
Next
'' Assign result to function output
DumpVariableMemory = strDumpBuffer & _
vbCrLf & String(81, Chr$(61)) & vbCrLf
Exit_Point:
Exit Function
'' Error Handling
DumpVariableMemory_Err:
LogError "modNYFixLibrary.DumpVariableMemory", Err.Number, Err.Description
DumpVariableMemory = String(81, Chr$(61)) & vbCrLf & _
"DumpFailed!" & vbCrLf & String(81, Chr$(61))
GoTo Exit_Point
Resume
End Function

关于memory - 在 VB6 应用程序中识别内存占用的工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/742671/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com